2016-01-01 04:33:14 +00:00
|
|
|
# Copyright (C) 2009-2016 Free Software Foundation, Inc.
|
2010-06-28 21:16:04 +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 inferiors to Python.
|
|
|
|
|
2010-10-01 17:03:50 +00:00
|
|
|
load_lib gdb-python.exp
|
2010-06-28 21:16:04 +00:00
|
|
|
|
* 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
|
|
|
|
|
2012-07-26 19:09:35 +00:00
|
|
|
if { [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable {debug}] != "" } {
|
2010-06-28 21:16:04 +00:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start with a fresh gdb.
|
|
|
|
clean_restart ${testfile}
|
|
|
|
|
|
|
|
# Skip all tests if Python scripting is not enabled.
|
|
|
|
if { [skip_python_tests] } { continue }
|
|
|
|
|
2010-11-12 21:44:49 +00:00
|
|
|
gdb_test_multiple "show endian" "getting target endian" {
|
|
|
|
-re ".*little endian.*$gdb_prompt $" {
|
|
|
|
set python_pack_char "<"
|
|
|
|
# pass silently
|
|
|
|
}
|
|
|
|
-re ".*big endian.*$gdb_prompt $" {
|
|
|
|
set python_pack_char ">"
|
|
|
|
# pass silently
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-28 21:16:04 +00:00
|
|
|
# The following tests require execution.
|
|
|
|
|
|
|
|
if ![runto_main] then {
|
|
|
|
fail "Can't run to main"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test basic gdb.Inferior attributes and methods.
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (inferiors)" "\\(<gdb.Inferior object at 0x\[\[:xdigit:\]\]+>,\\)" "verify inferiors list"
|
2010-06-28 21:16:04 +00:00
|
|
|
gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = %s' % (i0 == inferiors\[0\]))" " = True" "test equality comparison (true)"
|
|
|
|
gdb_test "python print ('result = %s' % i0.num)" " = \[0-9\]+" "test Inferior.num"
|
|
|
|
gdb_test "python print ('result = %s' % i0.pid)" " = \[0-9\]+" "test Inferior.pid"
|
|
|
|
gdb_test "python print ('result = %s' % i0.was_attached)" " = False" "test Inferior.was_attached"
|
|
|
|
gdb_test "python print (i0.threads ())" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
|
2010-06-28 21:16:04 +00:00
|
|
|
|
2012-07-26 19:09:35 +00:00
|
|
|
# Test the number of inferior threads.
|
|
|
|
|
|
|
|
gdb_breakpoint check_threads
|
|
|
|
gdb_continue_to_breakpoint "cont to check_threads" ".*pthread_barrier_wait.*"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (len (i0.threads ()))" "\r\n9" "test Inferior.threads 2"
|
2012-07-26 19:09:35 +00:00
|
|
|
|
|
|
|
# Proceed to the next test.
|
|
|
|
|
|
|
|
gdb_breakpoint [gdb_get_line_number "Break here."]
|
|
|
|
gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*"
|
|
|
|
|
2010-06-28 21:16:04 +00:00
|
|
|
# Test memory read and write operations.
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
|
|
|
|
"read str address" 0
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \
|
2010-06-28 21:16:04 +00:00
|
|
|
"read str contents" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
if { $gdb_py_is_py3k == 0 } {
|
|
|
|
gdb_py_test_silent_cmd "python a = 'a'" "" 0
|
|
|
|
} else {
|
|
|
|
gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0
|
|
|
|
}
|
|
|
|
gdb_py_test_silent_cmd "python str\[1\] = a" "change str" 0
|
2010-06-28 21:16:04 +00:00
|
|
|
gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
|
|
|
|
"write str" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "print (str)" " = \"hallo, testsuite\"" \
|
2010-06-28 21:16:04 +00:00
|
|
|
"ensure str was changed in the inferior"
|
|
|
|
|
|
|
|
# Test memory search.
|
|
|
|
|
|
|
|
set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
|
|
|
|
set dec_number {[0-9]+}
|
|
|
|
set history_prefix {[$][0-9]* = }
|
|
|
|
set newline {[\r\n]+}
|
|
|
|
set pattern_not_found "${newline}.None"
|
|
|
|
set one_pattern_found "${newline}.${dec_number}"
|
|
|
|
|
|
|
|
# Test string pattern.
|
|
|
|
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "string" {
|
|
|
|
gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161"
|
|
|
|
gdb_test "py search_buf = gdb.selected_frame ().read_var ('int8_search_buf')"
|
|
|
|
gdb_test_no_output "py start_addr = search_buf.address"
|
|
|
|
gdb_test_no_output "py length = search_buf.type.sizeof"
|
|
|
|
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa'))" \
|
|
|
|
"${one_pattern_found}" "find string pattern"
|
|
|
|
|
|
|
|
# Test not finding pattern because search range too small, with
|
|
|
|
# potential find at the edge of the range.
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, 10+3, 'aaaa'))" \
|
|
|
|
"${pattern_not_found}" "pattern not found at end of range"
|
|
|
|
|
|
|
|
# Increase the search range by 1 and we should find the pattern.
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, 10+3+1, 'aaa'))" \
|
|
|
|
"${one_pattern_found}" "pattern found at end of range"
|
|
|
|
}
|
2010-06-28 21:16:04 +00:00
|
|
|
|
|
|
|
# Import struct to pack the following patterns.
|
2011-03-02 15:17:01 +00:00
|
|
|
gdb_test_no_output "py from struct import *"
|
2010-06-28 21:16:04 +00:00
|
|
|
|
|
|
|
# Test 16-bit pattern.
|
|
|
|
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "16-bit" {
|
|
|
|
gdb_test_no_output "set int16_search_buf\[10\] = 0x1234"
|
|
|
|
gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')"
|
|
|
|
gdb_test_no_output "py start_addr = search_buf.address"
|
|
|
|
gdb_test_no_output "py length = search_buf.type.sizeof"
|
|
|
|
gdb_test_no_output "py pattern = pack('${python_pack_char}H',0x1234)"
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, length, pattern))" \
|
|
|
|
"${one_pattern_found}" "find 16-bit pattern, with value pattern"
|
|
|
|
}
|
2010-06-28 21:16:04 +00:00
|
|
|
|
|
|
|
# Test 32-bit pattern.
|
|
|
|
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "32-bit" {
|
|
|
|
gdb_test_no_output "set int32_search_buf\[10\] = 0x12345678"
|
|
|
|
gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')"
|
|
|
|
gdb_test_no_output "py start_addr = search_buf.address"
|
|
|
|
gdb_test_no_output "py length = search_buf.type.sizeof"
|
|
|
|
gdb_test_no_output "py pattern = pack('${python_pack_char}I',0x12345678)"
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, length, pattern))" \
|
|
|
|
"${one_pattern_found}" "find 32-bit pattern, with python pattern"
|
|
|
|
}
|
2010-06-28 21:16:04 +00:00
|
|
|
|
|
|
|
# Test 64-bit pattern.
|
|
|
|
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "64-bit" {
|
|
|
|
gdb_test_no_output "set int64_search_buf\[10\] = 0xfedcba9876543210LL"
|
|
|
|
gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')"
|
|
|
|
gdb_test_no_output "py start_addr = search_buf.address"
|
|
|
|
gdb_test_no_output "py length = search_buf.type.sizeof"
|
|
|
|
gdb_test_no_output "py pattern = pack('${python_pack_char}Q', 0xfedcba9876543210)"
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, length, pattern))" \
|
|
|
|
"${one_pattern_found}" "find 64-bit pattern, with value pattern"
|
|
|
|
}
|
2010-06-28 21:16:04 +00:00
|
|
|
|
|
|
|
# Test mixed-sized patterns.
|
|
|
|
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "mixed-sized" {
|
|
|
|
gdb_test_no_output "set *(int8_t*) &search_buf\[10\] = 0x62"
|
|
|
|
gdb_test_no_output "set *(int16_t*) &search_buf\[11\] = 0x6363"
|
|
|
|
gdb_test_no_output "set *(int32_t*) &search_buf\[13\] = 0x64646464"
|
|
|
|
gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('search_buf')"
|
|
|
|
gdb_test_no_output "py start_addr = search_buf\[0\].address"
|
|
|
|
gdb_test_no_output "py pattern1 = pack('B', 0x62)"
|
|
|
|
gdb_test_no_output "py pattern2 = pack('${python_pack_char}H', 0x6363)"
|
|
|
|
gdb_test_no_output "py pattern3 = pack('${python_pack_char}I', 0x64646464)"
|
|
|
|
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern1))" \
|
|
|
|
"${one_pattern_found}" "find mixed-sized pattern 1"
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern2))" \
|
|
|
|
"${one_pattern_found}" "find mixed-sized pattern 2"
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern3))" \
|
|
|
|
"${one_pattern_found}" "find mixed-sized pattern 3"
|
|
|
|
}
|
2010-06-28 21:16:04 +00:00
|
|
|
|
|
|
|
# Test search spanning a large range, in the particular case of native
|
|
|
|
# targets, test the search spanning multiple chunks.
|
|
|
|
# Remote targets may implement the search differently.
|
|
|
|
|
2013-06-07 17:31:09 +00:00
|
|
|
set CHUNK_SIZE 16000
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "large range" {
|
|
|
|
gdb_test_no_output "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678"
|
|
|
|
gdb_test_no_output "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678"
|
|
|
|
gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
|
|
|
|
gdb_test_no_output "py end_addr = start_addr + gdb.selected_frame ().read_var ('search_buf_size')"
|
|
|
|
gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0x12345678)"
|
|
|
|
|
|
|
|
gdb_test_no_output "py first = gdb.inferiors()\[0\].search_memory (start_addr,end_addr - start_addr, pattern)"
|
|
|
|
gdb_test "py print (first)" "${one_pattern_found}" "search spanning large range 1st result"
|
|
|
|
gdb_test_no_output "py start_addr = first + 1"
|
|
|
|
gdb_test_no_output "py second = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
|
|
|
|
gdb_test "py print (second)" "${one_pattern_found}" "search spanning large range 2nd result"
|
|
|
|
gdb_test_no_output "py start_addr = second + 1"
|
|
|
|
gdb_test_no_output "py third = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
|
|
|
|
gdb_test "py print (third)" "${pattern_not_found}" "search spanning large range 3rd result"
|
|
|
|
}
|
2010-06-28 21:16:04 +00:00
|
|
|
|
|
|
|
# For native targets, test a pattern straddling a chunk boundary.
|
|
|
|
|
|
|
|
if [isnative] {
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "straddling" {
|
|
|
|
gdb_test_no_output "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531"
|
|
|
|
gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0xfdb97531)"
|
|
|
|
gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
|
|
|
|
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern))" \
|
|
|
|
"${one_pattern_found}" "find pattern straddling chunk boundary"
|
|
|
|
}
|
2010-06-28 21:16:04 +00:00
|
|
|
}
|
2011-03-17 09:36:17 +00:00
|
|
|
|
|
|
|
# Test Inferior is_valid. This must always be the last test in
|
|
|
|
# this testcase as it kills the inferior.
|
|
|
|
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "is_valid" {
|
|
|
|
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get initial list" 1
|
|
|
|
gdb_test "python print (len(inf_list))" "1" "get inferior list length 1"
|
|
|
|
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
|
|
|
|
"check inferior validity 1"
|
|
|
|
|
|
|
|
gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
|
|
|
|
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
|
|
|
|
gdb_test "python print (len(inf_list))" "2" "get inferior list length 2"
|
|
|
|
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
|
|
|
|
"check inferior validity 2"
|
|
|
|
|
|
|
|
gdb_test "python print (inf_list\[1\].is_valid())" "True" \
|
|
|
|
"check inferior validity 3"
|
|
|
|
|
|
|
|
gdb_test_no_output "remove-inferiors 2" "remove-inferiors 3"
|
2016-01-12 01:12:38 +00:00
|
|
|
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
|
2015-11-24 18:11:19 +00:00
|
|
|
"check inferior validity 4"
|
|
|
|
|
2016-01-12 01:12:38 +00:00
|
|
|
gdb_test "python print (inf_list\[1\].is_valid())" "False" \
|
2015-11-24 18:11:19 +00:00
|
|
|
"check inferior validity 5"
|
|
|
|
}
|
2011-09-15 12:42:30 +00:00
|
|
|
|
|
|
|
# Test gdb.selected_inferior()
|
2015-11-24 18:11:19 +00:00
|
|
|
with_test_prefix "selected_inferior" {
|
|
|
|
gdb_test "inferior 1" ".*" "switch to first inferior"
|
|
|
|
gdb_test "py print (gdb.selected_inferior().num)" "1" "first inferior selected"
|
|
|
|
|
|
|
|
gdb_test "add-inferior" "Added inferior 3" "create new inferior"
|
|
|
|
gdb_test "inferior 3" ".*" "switch to third inferior"
|
|
|
|
gdb_test "py print (gdb.selected_inferior().num)" "3" "third inferior selected"
|
|
|
|
gdb_test "inferior 1" ".*" "switch back to first inferior"
|
|
|
|
gdb_test_no_output "remove-inferiors 3" "remove second inferior"
|
|
|
|
}
|