2014-01-01 03:54:24 +00:00
|
|
|
# Copyright (C) 2008-2014 Free Software Foundation, Inc.
|
2008-08-06 19:41:33 +00: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 values to Python.
|
|
|
|
|
2010-10-01 17:03:50 +00:00
|
|
|
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 python.c python-1.c
|
|
|
|
|
|
|
|
if {[build_executable $testfile.exp $testfile \
|
|
|
|
[list $srcfile $srcfile2] debug] == -1} {
|
2010-08-11 12:48:24 +00:00
|
|
|
return -1
|
|
|
|
}
|
2008-08-06 19:41:33 +00:00
|
|
|
|
2010-08-11 12:48:24 +00:00
|
|
|
# Start with a fresh gdb.
|
2008-08-06 19:41:33 +00:00
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
|
2014-08-14 06:16:56 +00:00
|
|
|
set remote_source2_py [gdb_remote_download host \
|
|
|
|
${srcdir}/${subdir}/source2.py]
|
|
|
|
|
2013-11-23 23:08:28 +00:00
|
|
|
# Do this instead of the skip_python_check.
|
|
|
|
# We want to do some tests when Python is not present.
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test_multiple "python print (23)" "verify python support" {
|
2008-08-06 19:41:33 +00:00
|
|
|
-re "not supported.*$gdb_prompt $" {
|
|
|
|
unsupported "python support is disabled"
|
2010-01-18 06:31:24 +00:00
|
|
|
|
|
|
|
# If Python is not supported, verify that sourcing a python script
|
|
|
|
# causes an error.
|
2014-08-14 06:16:56 +00:00
|
|
|
gdb_test "source $remote_source2_py" \
|
2011-10-18 14:14:01 +00:00
|
|
|
"Error in sourced command file:.*" \
|
|
|
|
"source source2.py when python disabled"
|
2014-03-22 06:44:39 +00:00
|
|
|
|
|
|
|
# Verify multi-line python commands cause an error.
|
|
|
|
gdb_py_test_multiple "multi-line python command" \
|
|
|
|
"python" "" \
|
|
|
|
"print (23)" "" \
|
|
|
|
"end" "not supported.*"
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_py_test_multiple "multi-line python command" \
|
|
|
|
"python" "" \
|
2012-12-10 21:22:21 +00:00
|
|
|
"print (23)" "" \
|
2008-08-06 19:41:33 +00:00
|
|
|
"end" "23"
|
|
|
|
|
|
|
|
gdb_py_test_multiple "show python command" \
|
|
|
|
"define zzq" "Type commands for definition of .* just \"end\"\\.*" \
|
|
|
|
"python" "" \
|
2012-12-10 21:22:21 +00:00
|
|
|
"print (23)" "" \
|
2008-08-06 19:41:33 +00:00
|
|
|
"end" "" \
|
|
|
|
"end" "" \
|
2012-12-10 21:22:21 +00:00
|
|
|
"show user zzq" "User command \"zzq\":.* python.*print \\(23\\).* end"
|
2008-08-16 20:36:30 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "indented multi-line python command" \
|
|
|
|
"python" "" \
|
|
|
|
"def foo ():" "" \
|
2012-12-10 21:22:21 +00:00
|
|
|
" print ('hello, world!')" "" \
|
2008-08-16 20:36:30 +00:00
|
|
|
"foo ()" "" \
|
|
|
|
"end" "hello, world!"
|
2009-05-28 00:40:24 +00:00
|
|
|
|
2014-08-14 06:16:56 +00:00
|
|
|
gdb_test "source $remote_source2_py" "yes" "source source2.py"
|
2010-01-18 06:31:24 +00:00
|
|
|
|
2011-10-27 15:46:11 +00:00
|
|
|
gdb_test "source -s source2.py" "yes" "source -s source2.py"
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.current_objfile())" "None"
|
|
|
|
gdb_test "python print (gdb.objfiles())" "\\\[\\\]"
|
2010-06-08 16:41:45 +00:00
|
|
|
|
|
|
|
# Test http://bugs.python.org/issue4434 workaround in configure.ac
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python import itertools; print ('IMPOR'+'TED')" "IMPORTED" "pythonX.Y/lib-dynload/*.so"
|
2010-06-25 18:15:18 +00:00
|
|
|
|
|
|
|
gdb_test_no_output \
|
|
|
|
"python x = gdb.execute('printf \"%d\", 23', to_string = True)"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (x)" "23"
|
2010-08-07 15:00:39 +00:00
|
|
|
|
2010-08-11 20:54:12 +00:00
|
|
|
# Test post_event.
|
|
|
|
gdb_py_test_multiple "post event insertion" \
|
|
|
|
"python" "" \
|
|
|
|
"someVal = 0" "" \
|
2010-08-16 18:01:40 +00:00
|
|
|
"class Foo(object):" "" \
|
2010-08-11 20:54:12 +00:00
|
|
|
" def __call__(self):" "" \
|
|
|
|
" global someVal" "" \
|
|
|
|
" someVal += 1" "" \
|
|
|
|
"gdb.post_event(Foo())" "" \
|
|
|
|
"end" ""
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (someVal)" "1" "test post event execution"
|
2010-08-11 20:54:12 +00:00
|
|
|
gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" "Test non callable class"
|
|
|
|
|
2010-08-07 15:00:39 +00:00
|
|
|
# Test (no) pagination of the executed command.
|
|
|
|
gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.}
|
|
|
|
set lines 10
|
|
|
|
gdb_test_no_output "set height $lines"
|
|
|
|
|
|
|
|
set test "verify pagination beforehand"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test_multiple "python print (\"\\n\" * $lines)" $test {
|
2011-09-30 15:07:33 +00:00
|
|
|
-re "---Type <return>" {
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re " to continue, or q <return>" {
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re " to quit---$" {
|
2010-08-07 15:00:39 +00:00
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
2012-06-27 13:37:26 +00:00
|
|
|
gdb_test "q" "Quit.*Error while executing Python.*" "verify pagination beforehand: q"
|
2010-08-07 15:00:39 +00:00
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python if gdb.execute('python print (\"\\\\n\" * $lines)', to_string=True) == \"\\n\" * [expr $lines + 1]: print (\"yes\")" "yes" "gdb.execute does not page"
|
2010-08-07 15:00:39 +00:00
|
|
|
|
|
|
|
set test "verify pagination afterwards"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test_multiple "python print (\"\\n\" * $lines)" $test {
|
2011-09-30 15:07:33 +00:00
|
|
|
-re "---Type <return>" {
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re " to continue, or q <return>" {
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re " to quit---$" {
|
2010-08-07 15:00:39 +00:00
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
2012-06-27 13:37:26 +00:00
|
|
|
gdb_test "q" "Quit.*Error while executing Python.*" "verify pagination afterwards: q"
|
2010-08-11 12:48:24 +00:00
|
|
|
|
2010-09-11 16:00:27 +00:00
|
|
|
gdb_test_no_output "set height 0"
|
|
|
|
|
|
|
|
gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect help from uiout"
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (a)" ".*aliases -- Aliases of other commands.*" "verify help to uiout"
|
2010-09-11 16:00:27 +00:00
|
|
|
|
2010-11-23 13:33:23 +00:00
|
|
|
# Test PR 12212, using InfThread.selected_thread() when no inferior is
|
|
|
|
# loaded.
|
|
|
|
gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (nothread == None)" "True" "Ensure that no threads are returned"
|
2010-11-23 13:33:23 +00:00
|
|
|
|
2012-09-20 20:54:11 +00:00
|
|
|
gdb_py_test_multiple "register atexit function" \
|
|
|
|
"python" "" \
|
|
|
|
"import atexit" "" \
|
|
|
|
"def printit(arg):" "" \
|
2012-12-10 21:22:21 +00:00
|
|
|
" print (arg)" "" \
|
2012-09-20 20:54:11 +00:00
|
|
|
"atexit.register(printit, 'good bye world')" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
send_gdb "quit\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "good bye world" {
|
|
|
|
pass "atexit handling"
|
|
|
|
}
|
|
|
|
default {
|
|
|
|
fail "atexit handling"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-11 12:48:24 +00:00
|
|
|
# Start with a fresh gdb.
|
|
|
|
clean_restart ${testfile}
|
|
|
|
|
|
|
|
# The following tests require execution.
|
|
|
|
|
|
|
|
if ![runto_main] then {
|
|
|
|
fail "Can't run to main"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
PR gdb/13860: make -interpreter-exec console "list" behave more like "list".
I noticed that "list" behaves differently in CLI vs MI. Particularly:
$ ./gdb -nx -q ./testsuite/gdb.mi/mi-cli
Reading symbols from /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/mi-cli...done.
(gdb) start
Temporary breakpoint 1 at 0x40054d: file ../../../src/gdb/testsuite/gdb.mi/basics.c, line 62.
Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/mi-cli
Temporary breakpoint 1, main () at ../../../src/gdb/testsuite/gdb.mi/basics.c:62
62 callee1 (2, "A string argument.", 3.5);
(gdb) list
57 {
58 }
59
60 main ()
61 {
62 callee1 (2, "A string argument.", 3.5);
63 callee1 (2, "A string argument.", 3.5);
64
65 do_nothing (); /* Hello, World! */
66
(gdb)
Note the list started at line 57. IOW, the program stopped at line
62, and GDB centered the list on that.
compare with:
$ ./gdb -nx -q ./testsuite/gdb.mi/mi-cli -i=mi
=thread-group-added,id="i1"
~"Reading symbols from /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/mi-cli..."
~"done.\n"
(gdb)
start
&"start\n"
...
~"\nTemporary breakpoint "
~"1, main () at ../../../src/gdb/testsuite/gdb.mi/basics.c:62\n"
~"62\t callee1 (2, \"A string argument.\", 3.5);\n"
*stopped,reason="breakpoint-hit",disp="del",bkptno="1",frame={addr="0x000000000040054d",func="main",args=[],file="../../../src/gdb/testsuite/gdb.mi/basics.c",fullname="/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.mi/basics.c",line="62"},thread-id="1",stopped-threads="all",core="0"
=breakpoint-deleted,id="1"
(gdb)
-interpreter-exec console list
~"62\t callee1 (2, \"A string argument.\", 3.5);\n"
~"63\t callee1 (2, \"A string argument.\", 3.5);\n"
~"64\t\n"
~"65\t do_nothing (); /* Hello, World! */\n"
~"66\t\n"
~"67\t callme (1);\n"
~"68\t callme (2);\n"
~"69\t\n"
~"70\t return 0;\n"
~"71\t}\n"
^done
(gdb)
Here the list starts at line 62, where the program was stopped.
This happens because print_stack_frame, called from both normal_stop
and mi_on_normal_stop, is the function responsible for setting the
current sal from the selected frame, overrides the PRINT_WHAT
argument, and only after that does it decide whether to center the
current sal line or not, based on the overridden value, and it will
always decide false.
(The print_stack_frame call in mi_on_normal_stop is a little different
from the call in normal_stop, in that it is an unconditional
SRC_AND_LOC call. A future patch will make those uniform.)
A previous version of this patch made MI uniform with CLI here, by
making print_stack_frame also center when MI is active. That changed
the output of a "list" command in mi-cli.exp, to expect line 57
instead of 62, as per the example above.
However, looking deeper, that list in question is the first "list"
after the program stops, and right after the stop, before the "list",
the test did "set listsize 1". Let's try the same thing with the CLI:
(gdb) start
62 callee1 (2, "A string argument.", 3.5);
(gdb) set listsize 1
(gdb) list
57 {
Huh, that's unexpected. Why the 57? It's because print_stack_frame,
called in reaction to the breakpoint stop, expecting the next "list"
to show 10 lines (the listsize at the time) around line 62, sets the
lines listed range to 57-67 (62 +/- 5). If the user changes the
listsize before "list", why would we still show that range? Looks
bogus to me.
So the fix for this whole issue should be delay trying to center the
listing to until actually listing, so that the correct listsize can be
taken into account. This makes MI and CLI uniform too, as it deletes
the center code from print_stack_frame.
A series of tests are added to list.exp to cover this. mi-cli.exp was
after all correct all along, but it now gains an additional test that
lists lines with listsize 10, to ensure the centering is consistent
with CLI's.
One related Python test changed related output -- it's a test that
prints the line number after stopping for a breakpoint, similar to the
new list.exp tests. Previously we'd print the stop line minus 5 (due
to the premature centering), now we print the stop line. I think
that's a good change.
Tested on x86_64 Fedora 20.
gdb/
2014-05-21 Pedro Alves <palves@redhat.com>
* cli/cli-cmds.c (list_command): Handle the first "list" after the
current source line having changed.
* frame.h (set_current_sal_from_frame): Remove 'center' parameter.
* infrun.c (normal_stop): Adjust call to
set_current_sal_from_frame.
* source.c (clear_lines_listed_range): New function.
(set_current_source_symtab_and_line, identify_source_line): Clear
the lines listed range.
(line_info): Handle the first "info line" after the current source
line having changed.
* stack.c (print_stack_frame): Remove center handling.
(set_current_sal_from_frame): Remove 'center' parameter. Don't
center sal.line.
gdb/testsuite/
2014-05-21 Pedro Alves <palves@redhat.com>
* gdb.base/list.exp (build_pattern, test_list): New procedures.
Use them to test variations of "list" after reaching a breakpoint.
* gdb.mi/mi-cli.exp (line_main_callme_2): New global.
Test "list" with listsize 10 after reaching a breakpoint.
* gdb.python/python.exp (decode_line current location line
number): Adjust expected line number.
2014-05-21 22:15:27 +00:00
|
|
|
set lineno [gdb_get_line_number "Break to end."]
|
|
|
|
runto $lineno
|
2010-08-11 12:48:24 +00:00
|
|
|
|
|
|
|
# Test gdb.decode_line.
|
|
|
|
gdb_test "python gdb.decode_line(\"main.c:43\")" \
|
2010-11-12 20:49:43 +00:00
|
|
|
"gdb.error: No source file named main.c.*" "test decode_line no source named main"
|
2010-08-11 12:48:24 +00:00
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (len(symtab))" "2" "Test decode_line current location"
|
|
|
|
gdb_test "python print (symtab\[0\])" "None" "Test decode_line expression parse"
|
|
|
|
gdb_test "python print (len(symtab\[1\]))" "1" "Test decode_line current location"
|
|
|
|
gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*gdb.python/python.c.*" "Test decode_line current locationn filename"
|
PR gdb/13860: make -interpreter-exec console "list" behave more like "list".
I noticed that "list" behaves differently in CLI vs MI. Particularly:
$ ./gdb -nx -q ./testsuite/gdb.mi/mi-cli
Reading symbols from /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/mi-cli...done.
(gdb) start
Temporary breakpoint 1 at 0x40054d: file ../../../src/gdb/testsuite/gdb.mi/basics.c, line 62.
Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/mi-cli
Temporary breakpoint 1, main () at ../../../src/gdb/testsuite/gdb.mi/basics.c:62
62 callee1 (2, "A string argument.", 3.5);
(gdb) list
57 {
58 }
59
60 main ()
61 {
62 callee1 (2, "A string argument.", 3.5);
63 callee1 (2, "A string argument.", 3.5);
64
65 do_nothing (); /* Hello, World! */
66
(gdb)
Note the list started at line 57. IOW, the program stopped at line
62, and GDB centered the list on that.
compare with:
$ ./gdb -nx -q ./testsuite/gdb.mi/mi-cli -i=mi
=thread-group-added,id="i1"
~"Reading symbols from /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/mi-cli..."
~"done.\n"
(gdb)
start
&"start\n"
...
~"\nTemporary breakpoint "
~"1, main () at ../../../src/gdb/testsuite/gdb.mi/basics.c:62\n"
~"62\t callee1 (2, \"A string argument.\", 3.5);\n"
*stopped,reason="breakpoint-hit",disp="del",bkptno="1",frame={addr="0x000000000040054d",func="main",args=[],file="../../../src/gdb/testsuite/gdb.mi/basics.c",fullname="/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.mi/basics.c",line="62"},thread-id="1",stopped-threads="all",core="0"
=breakpoint-deleted,id="1"
(gdb)
-interpreter-exec console list
~"62\t callee1 (2, \"A string argument.\", 3.5);\n"
~"63\t callee1 (2, \"A string argument.\", 3.5);\n"
~"64\t\n"
~"65\t do_nothing (); /* Hello, World! */\n"
~"66\t\n"
~"67\t callme (1);\n"
~"68\t callme (2);\n"
~"69\t\n"
~"70\t return 0;\n"
~"71\t}\n"
^done
(gdb)
Here the list starts at line 62, where the program was stopped.
This happens because print_stack_frame, called from both normal_stop
and mi_on_normal_stop, is the function responsible for setting the
current sal from the selected frame, overrides the PRINT_WHAT
argument, and only after that does it decide whether to center the
current sal line or not, based on the overridden value, and it will
always decide false.
(The print_stack_frame call in mi_on_normal_stop is a little different
from the call in normal_stop, in that it is an unconditional
SRC_AND_LOC call. A future patch will make those uniform.)
A previous version of this patch made MI uniform with CLI here, by
making print_stack_frame also center when MI is active. That changed
the output of a "list" command in mi-cli.exp, to expect line 57
instead of 62, as per the example above.
However, looking deeper, that list in question is the first "list"
after the program stops, and right after the stop, before the "list",
the test did "set listsize 1". Let's try the same thing with the CLI:
(gdb) start
62 callee1 (2, "A string argument.", 3.5);
(gdb) set listsize 1
(gdb) list
57 {
Huh, that's unexpected. Why the 57? It's because print_stack_frame,
called in reaction to the breakpoint stop, expecting the next "list"
to show 10 lines (the listsize at the time) around line 62, sets the
lines listed range to 57-67 (62 +/- 5). If the user changes the
listsize before "list", why would we still show that range? Looks
bogus to me.
So the fix for this whole issue should be delay trying to center the
listing to until actually listing, so that the correct listsize can be
taken into account. This makes MI and CLI uniform too, as it deletes
the center code from print_stack_frame.
A series of tests are added to list.exp to cover this. mi-cli.exp was
after all correct all along, but it now gains an additional test that
lists lines with listsize 10, to ensure the centering is consistent
with CLI's.
One related Python test changed related output -- it's a test that
prints the line number after stopping for a breakpoint, similar to the
new list.exp tests. Previously we'd print the stop line minus 5 (due
to the premature centering), now we print the stop line. I think
that's a good change.
Tested on x86_64 Fedora 20.
gdb/
2014-05-21 Pedro Alves <palves@redhat.com>
* cli/cli-cmds.c (list_command): Handle the first "list" after the
current source line having changed.
* frame.h (set_current_sal_from_frame): Remove 'center' parameter.
* infrun.c (normal_stop): Adjust call to
set_current_sal_from_frame.
* source.c (clear_lines_listed_range): New function.
(set_current_source_symtab_and_line, identify_source_line): Clear
the lines listed range.
(line_info): Handle the first "info line" after the current source
line having changed.
* stack.c (print_stack_frame): Remove center handling.
(set_current_sal_from_frame): Remove 'center' parameter. Don't
center sal.line.
gdb/testsuite/
2014-05-21 Pedro Alves <palves@redhat.com>
* gdb.base/list.exp (build_pattern, test_list): New procedures.
Use them to test variations of "list" after reaching a breakpoint.
* gdb.mi/mi-cli.exp (line_main_callme_2): New global.
Test "list" with listsize 10 after reaching a breakpoint.
* gdb.python/python.exp (decode_line current location line
number): Adjust expected line number.
2014-05-21 22:15:27 +00:00
|
|
|
gdb_test "python print (symtab\[1\]\[0\].line)" "$lineno" "Test decode_line current location line number"
|
2010-08-11 12:48:24 +00:00
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "test decode_line python.c:26" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (len(symtab))" "2" "Test decode_line python.c:26 length"
|
|
|
|
gdb_test "python print (symtab\[0\])" "if foo" "Test decode_line expression parse"
|
|
|
|
gdb_test "python print (len(symtab\[1\]))" "1" "Test decode_line python.c:26 length"
|
|
|
|
gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*gdb.python/python.c.*" "Test decode_line python.c:26 filename"
|
|
|
|
gdb_test "python print (symtab\[1\]\[0\].line)" "26" "Test decode_line python.c:26 line number"
|
2010-08-11 12:48:24 +00:00
|
|
|
|
|
|
|
gdb_test "python gdb.decode_line(\"randomfunc\")" \
|
2010-11-12 20:49:43 +00:00
|
|
|
"gdb.error: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
|
2010-08-11 12:48:24 +00:00
|
|
|
gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (len(symtab))" "2" "Test decode_line func1 length"
|
|
|
|
gdb_test "python print (len(symtab\[1\]))" "1" "Test decode_line func1 length"
|
|
|
|
gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*gdb.python/python-1.c.*" "Test decode_line func1 filename"
|
|
|
|
gdb_test "python print (symtab\[1\]\[0\].line)" "19" "Test decode_line func1 line number"
|
2012-03-30 19:16:52 +00:00
|
|
|
gdb_py_test_silent_cmd {python symtab = gdb.decode_line ("func1,func2")} \
|
|
|
|
"test decode_line func1,func2" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test {python print (symtab[0])} ",func2" "stop at comma in linespec"
|
2011-03-18 08:44:47 +00:00
|
|
|
|
|
|
|
# gdb.write
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (sys.stderr)" ".*gdb.GdbOutputErrorFile (instance|object) at.*" "Test stderr location"
|
|
|
|
gdb_test "python print (sys.stdout)" ".*gdb.GdbOutputFile (instance|object) at.*" "Test stdout location"
|
2011-03-18 08:44:47 +00:00
|
|
|
gdb_test "python gdb.write(\"Foo\\n\")" "Foo" "Test default write"
|
|
|
|
gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error stream" "Test stderr write"
|
|
|
|
gdb_test "python gdb.write(\"Normal stream\\n\", stream=gdb.STDOUT)" "Normal stream" "Test stdout write"
|
|
|
|
gdb_test "python gdb.write(\"Log stream\\n\", stream=gdb.STDLOG)" "Log stream" "Test stdlog write"
|
2011-07-11 13:07:38 +00:00
|
|
|
|
2013-10-01 20:36:01 +00:00
|
|
|
# Turn on full stack printing for subsequent tests.
|
2011-12-16 15:55:40 +00:00
|
|
|
gdb_py_test_silent_cmd "set python print-stack full" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"Set print-stack full for prompt tests" 1
|
2011-07-21 11:03:48 +00:00
|
|
|
|
|
|
|
# Test prompt substituion
|
|
|
|
|
|
|
|
gdb_py_test_multiple "prompt substitution" \
|
|
|
|
"python" "" \
|
|
|
|
"someCounter = 0" "" \
|
|
|
|
"def prompt(current):" "" \
|
|
|
|
" global someCounter" "" \
|
|
|
|
" if (current == \"testfake \"):" "" \
|
|
|
|
" return None" "" \
|
|
|
|
" someCounter = someCounter + 1" "" \
|
|
|
|
" return \"py prompt \" + str (someCounter) + \" \"" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_py_test_multiple "prompt substitution readline" \
|
|
|
|
"python" "" \
|
|
|
|
"pCounter = 0" "" \
|
|
|
|
"def program_prompt(current):" "" \
|
|
|
|
" global pCounter" "" \
|
|
|
|
" if (current == \">\"):" "" \
|
|
|
|
" pCounter = pCounter + 1" "" \
|
|
|
|
" return \"python line \" + str (pCounter) + \": \"" "" \
|
|
|
|
" return None" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
set newprompt "py prompt 1"
|
|
|
|
set newprompt2 "py prompt 2"
|
|
|
|
set testfake "testfake"
|
|
|
|
|
|
|
|
gdb_test_multiple "python gdb.prompt_hook = prompt" "set the hook" {
|
|
|
|
-re "\[\r\n\]$newprompt $" {
|
|
|
|
pass "set hook"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "set prompt testfake " "set testfake prompt in GDB" {
|
|
|
|
-re "\[\r\n\]$testfake $" {
|
|
|
|
pass "set prompt testfake"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "show prompt" "show testfake prompt" {
|
|
|
|
-re "Gdb's prompt is \"$testfake \"..* $" {
|
|
|
|
pass "show prompt shows guarded prompt"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "set prompt blah " "set blah in GDB" {
|
|
|
|
-re "\[\r\n\]$newprompt2 $" {
|
|
|
|
pass "set prompt blah overriden"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "python gdb.prompt_hook = None" "Delete hook" {
|
|
|
|
-re "\[\r\n\]$newprompt2 $" {
|
|
|
|
pass "Delete old hook"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "set prompt $gdb_prompt " "set default prompt" {
|
|
|
|
-re "\[\r\n\]$gdb_prompt $" {
|
|
|
|
pass "set default prompt"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "python gdb.prompt_hook = program_prompt" "set the hook" {
|
|
|
|
-re "\[\r\n\]$gdb_prompt $" {
|
|
|
|
pass "set programming hook"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "python" "test we ignore substituion for seconday prompts" {
|
|
|
|
-re "\r\n>$" {
|
|
|
|
pass "readline secondary are not substituted"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "end" "end programming" {
|
|
|
|
-re "\[\r\n\]$gdb_prompt $" {
|
|
|
|
pass "end programming"
|
|
|
|
}
|
|
|
|
}
|
2011-08-17 10:41:22 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "prompt substitution readline" \
|
|
|
|
"python" "" \
|
|
|
|
"import gdb.command.prompt" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test_multiple "set extended-prompt one two three " \
|
|
|
|
"set basic extended prompt" {
|
|
|
|
-re "\[\r\n\]one two three $" {
|
|
|
|
pass "set basic extended prompt"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "set extended-prompt \\w " \
|
|
|
|
"set extended prompt working directory" {
|
|
|
|
-re "\[\r\n\].*gdb.*testsuite.* $" {
|
|
|
|
pass "set extended prompt working directory"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_multiple "set extended-prompt some param \\p{python print-stack} " \
|
|
|
|
"set extended prompt parameter" {
|
2011-12-16 15:55:40 +00:00
|
|
|
-re "\[\r\n\]some param full $" {
|
2011-08-17 10:41:22 +00:00
|
|
|
pass "set extended prompt parameter"
|
|
|
|
}
|
|
|
|
}
|
2011-12-16 15:55:40 +00:00
|
|
|
|
|
|
|
# Start with a fresh gdb.
|
|
|
|
clean_restart ${testfile}
|
|
|
|
|
|
|
|
# The following tests require execution.
|
|
|
|
|
|
|
|
if ![runto_main] then {
|
|
|
|
fail "Can't run to main"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# print-stack settings
|
|
|
|
gdb_test "show python print-stack" \
|
|
|
|
"The mode of Python stack printing on error is \"message\".*" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"Test print-stack show setting. Default is message."
|
2011-12-16 15:55:40 +00:00
|
|
|
gdb_py_test_silent_cmd "set python print-stack full" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"Test print-stack set setting to full" 1
|
2011-12-16 15:55:40 +00:00
|
|
|
gdb_test "show python print-stack" \
|
|
|
|
"The mode of Python stack printing on error is \"full\".*" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"Test print-stack show setting to full"
|
2011-12-16 15:55:40 +00:00
|
|
|
gdb_py_test_silent_cmd "set python print-stack none" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"Test print-stack set setting to none" 1
|
2011-12-16 15:55:40 +00:00
|
|
|
gdb_test "show python print-stack" \
|
|
|
|
"The mode of Python stack printing on error is \"none\".*" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"Test print-stack show setting to none"
|
2011-12-16 15:55:40 +00:00
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "set python print-stack message" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"Test print-stack set setting to message" 1
|
2011-12-16 15:55:40 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "prompt substitution readline" \
|
|
|
|
"python" "" \
|
|
|
|
"pCounter = 0" "" \
|
|
|
|
"def error_prompt(current):" "" \
|
|
|
|
" raise RuntimeError(\"Python exception called\")" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" {
|
2012-12-11 20:54:52 +00:00
|
|
|
-re "Python Exception (exceptions.RuntimeError|<(type 'exceptions.|class ')RuntimeError'>) Python exception called.*" {
|
2011-12-16 15:55:40 +00:00
|
|
|
pass "set hook"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python gdb.prompt_hook = None" \
|
|
|
|
"set the hook to default" 1
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "set python print-stack full" \
|
2013-10-01 20:36:01 +00:00
|
|
|
"set print-stack full for prompt error test" 1
|
2011-12-16 15:55:40 +00:00
|
|
|
|
|
|
|
gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" {
|
|
|
|
-re "Traceback.*File.*line.*RuntimeError.*Python exception called.*" {
|
|
|
|
pass "set hook"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python gdb.prompt_hook = None" \
|
|
|
|
"set the hook to default" 1
|
2012-05-13 11:33:44 +00:00
|
|
|
|
|
|
|
# Start with a fresh gdb.
|
|
|
|
clean_restart ${testfile}
|
|
|
|
|
|
|
|
# The following tests require execution.
|
|
|
|
|
|
|
|
if ![runto_main] then {
|
|
|
|
fail "Can't run to main"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
runto [gdb_get_line_number "Break at func2 call site."]
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python line = gdb.selected_frame().find_sal().line" "Get line number of func2 call site" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line == line)" "True" "Test find_pc_line at func2 call site"
|
2012-05-13 11:33:44 +00:00
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "step" "Step into func2" 1
|
|
|
|
gdb_py_test_silent_cmd "up" "Step out of func2" 1
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line > line)" "True" "Test find_pc_line with resume address"
|