diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2010-06-28 21:16:04 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2010-06-28 21:16:04 +0000 |
commit | 595939dea136aa2721a24e6a71edba78e80fb3f5 (patch) | |
tree | 2a3c77226eb99b4b603ecb343fb060aff873e84b /gdb/testsuite/gdb.python | |
parent | 4802450ac95e6cb976fa8b35f194f91a8a4fd4ea (diff) | |
download | gdb-595939dea136aa2721a24e6a71edba78e80fb3f5.zip gdb-595939dea136aa2721a24e6a71edba78e80fb3f5.tar.gz gdb-595939dea136aa2721a24e6a71edba78e80fb3f5.tar.bz2 |
2010-06-28 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* value.c (pack_unsigned_long): New function.
(value_from_ulongest): New function.
* value.h (value_from_ulongest): Declare.
* python/python.c (_initialize_python): Call
gdbpy_initialize_thread and gdbpy_initialize_inferior.
* python/python-internal.h: Define thread_object.
(gdbpy_inferiors, gdbpy_selected_thread)
(frame_info_to_frame_object, create_thread_object)
(find_thread_object, find_inferior_object)
(gdbpy_initialize_thread, gdbpy_initialize_inferiors)
(gdbpy_is_value_object, get_addr_from_python): Declare.
* python/py-value.c (builtin_type_upylong): Define.
(convert_value_from_python): Add logic for ulongest.
(gdbpy_is_value_object): New function.
* python/py-utils.c (get_addr_from_python): New function.
* python/py-frame.c (frame_info_to_frame_object): Return a PyObject.
(gdbpy_selected_frame): Use PyObject over frame_info.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-inferior and
py-infthread.
(SUBDIR_PYTHON_SRCS): Likewise.
(py-inferior.o): New Rule.
(py-infthread.o): New Rule.
* python/py-inferior.c: New File.
* python/py-infthread.c: New File.
2010-06-28 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.texinfo (Inferiors In Python): New node.
* gdb.texinfo (Threads In Python): New node.
2010-06-28 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.python/py-inferior.c: New File.
* gdb.python/py-infthread.c: New File.
* gdb.python/py-inferior.exp: New File.
* gdb.python/py-infthread.exp: New File.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/Makefile.in | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-inferior.c | 49 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-inferior.exp | 191 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-infthread.c | 14 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-infthread.exp | 53 |
5 files changed, 308 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.python/Makefile.in b/gdb/testsuite/gdb.python/Makefile.in index c6a2678..660941d 100644 --- a/gdb/testsuite/gdb.python/Makefile.in +++ b/gdb/testsuite/gdb.python/Makefile.in @@ -2,7 +2,7 @@ VPATH = @srcdir@ srcdir = @srcdir@ EXECUTABLES = py-type py-value py-prettyprint py-template py-block \ - py-symbol py-mi py-breakpoint + py-symbol py-mi py-breakpoint py-inferior py-infthread all info install-info dvi install uninstall installcheck check: @echo "Nothing to be done for $@..." diff --git a/gdb/testsuite/gdb.python/py-inferior.c b/gdb/testsuite/gdb.python/py-inferior.c new file mode 100644 index 0000000..0b48299 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-inferior.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> + +#define CHUNK_SIZE 16000 /* same as findcmd.c's */ +#define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */ + +static int8_t int8_search_buf[100]; +static int16_t int16_search_buf[100]; +static int32_t int32_search_buf[100]; +static int64_t int64_search_buf[100]; + +static char *search_buf; +static int search_buf_size; + +static int x; + + +int f2 (int a) +{ + char *str = "hello, testsuite"; + + puts (str); /* Break here. */ + + return ++a; +} + +int f1 (int a, int b) +{ + return f2(a) + b; +} + +static void +init_bufs () +{ + search_buf_size = BUF_SIZE; + search_buf = malloc (search_buf_size); + if (search_buf == NULL) + exit (1); + memset (search_buf, 'x', search_buf_size); +} + +int main (int argc, char *argv[]) +{ + init_bufs (); + + return f1 (1, 2); +} diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp new file mode 100644 index 0000000..309ae8c --- /dev/null +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -0,0 +1,191 @@ +# Copyright (C) 2009, 2010 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 inferiors to Python. + +if $tracelevel then { + strace $tracelevel +} + +# Run a command in GDB, and report a failure if a Python exception is thrown. +# If report_pass is true, report a pass if no exception is thrown. +proc gdb_py_test_silent_cmd {cmd name report_pass} { + global gdb_prompt + + gdb_test_multiple $cmd $name { + -re "Traceback.*$gdb_prompt $" { fail $name } + -re "$gdb_prompt $" { if $report_pass { pass $name } } + } +} + +set testfile "py-inferior" +set srcfile ${testfile}.c +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { + return -1 +} + +# Start with a fresh gdb. +clean_restart ${testfile} + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +# The following tests require execution. + +if ![runto_main] then { + fail "Can't run to main" + return 0 +} + +runto [gdb_get_line_number "Break here."] + +# Test basic gdb.Inferior attributes and methods. + +gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1 +gdb_test "python print inferiors" "\\(<gdb.Inferior object at 0x\[\[:xdigit:\]\]+>,\\)" "verify inferiors list" +gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0 + +gdb_test "python print 'result =', i0 == inferiors\[0\]" " = True" "test equality comparison (true)" +gdb_test "python print 'result =', i0.num" " = \[0-9\]+" "test Inferior.num" +gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid" +gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached" +gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads" + +# Test memory read and write operations. + +gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \ + "read str address" 0 +gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5)" \ + "read str contents" 1 +gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0 +gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \ + "write str" 1 +gdb_test "print str" " = 0x\[\[:xdigit:\]\]+ \"hallo, testsuite\"" \ + "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. + +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 "py start_addr = search_buf.address" "" "" +gdb_test "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" + +# Import struct to pack the following patterns. +gdb_test "py from struct import *" "" "" + +# Test 16-bit pattern. + +gdb_test "set int16_search_buf\[10\] = 0x1234" "" "" +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')" "" "" +gdb_test "py start_addr = search_buf.address" "" "" +gdb_test "py length = search_buf.type.sizeof" "" "" +gdb_test "py pattern = pack('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" + +# Test 32-bit pattern. + +gdb_test "set int32_search_buf\[10\] = 0x12345678" "" "" +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')" "" "" +gdb_test "py start_addr = search_buf.address" "" "" +gdb_test "py length = search_buf.type.sizeof" "" "" +gdb_test "py pattern = pack('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" + +# Test 64-bit pattern. + +gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" "" +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')" "" "" +gdb_test "py start_addr = search_buf.address" "" "" +gdb_test "py length = search_buf.type.sizeof" "" "" +gdb_test "py pattern = pack('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" + +# Test mixed-sized patterns. + +gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" "" +gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" "" +gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" "" +gdb_test "py search_buf = gdb.selected_frame ().read_var ('search_buf')" "" "" +gdb_test "py start_addr = search_buf\[0\].address" "" "" +gdb_test "py pattern1 = pack('B', 0x62)" "" "" +gdb_test "py pattern2 = pack('H', 0x6363)" "" "" +gdb_test "py pattern3 = pack('I', 0x64646464)" "" "" + +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern1)" \ + "${one_pattern_found}" "find mixed-sized pattern" +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern2)" \ + "${one_pattern_found}" "find mixed-sized pattern" +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern3)" \ + "${one_pattern_found}" "find mixed-sized pattern" + +# 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. + +set CHUNK_SIZE 16000 ; + +gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" "" +gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" "" +gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" "" +gdb_test "py length = gdb.selected_frame ().read_var ('search_buf_size')" "" "" +gdb_test "py pattern = pack('I', 0x12345678)" "" "" +gdb_test "py first = gdb.inferiors()\[0\].search_memory (start_addr,length, pattern)" "" "" +gdb_test "py print first" "${one_pattern_found}" "search spanning large range 1st result" +gdb_test "py start_addr = first + 1" +gdb_test "py second = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" "" "" +gdb_test "py print second" "${one_pattern_found}" "search spanning large range 2nd result" +gdb_test "py start_addr = second + 1" +gdb_test "py third = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" "" "" +gdb_test "py print third" "${pattern_not_found}" "search spanning large range 3rd result" + +# For native targets, test a pattern straddling a chunk boundary. + +if [isnative] { + gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" "" + gdb_test "py pattern = pack('I', 0xfdb97531)" "" "" + gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" "" + gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \ + "${one_pattern_found}" "find pattern straddling chunk boundary" +} diff --git a/gdb/testsuite/gdb.python/py-infthread.c b/gdb/testsuite/gdb.python/py-infthread.c new file mode 100644 index 0000000..22eb9f2 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-infthread.c @@ -0,0 +1,14 @@ +int f2 (int a) +{ + return ++a; +} + +int f1 (int a, int b) +{ + return f2(a) + b; +} + +int main (int argc, char *argv[]) +{ + return f1 (1, 2); +} diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp new file mode 100644 index 0000000..a25d0b5 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-infthread.exp @@ -0,0 +1,53 @@ +# Copyright (C) 2009, 2010 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 inferior threads to Python. + +if $tracelevel then { + strace $tracelevel +} + +set testfile "py-infthread" +set srcfile ${testfile}.c +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { + return -1 +} + +# Start with a fresh gdb. +clean_restart ${testfile} + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +# The following tests require execution. + +if ![runto_main] then { + fail "Can't run to main" + return 0 +} + +runto [gdb_get_line_number "Break here."] + +# Test basic gdb.Inferior attributes and methods. + +gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1 +gdb_test "python print t0" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object" +gdb_test "python print 'result =', t0.num" " = \[0-9\]+" "test Inferior.num" +gdb_test "python print 'result =', t0.ptid" " = \\(\[0-9\]+, \[0-9\]+, \[0-9\]+\\)" "test InferiorThread.ptid" + +gdb_test "python print 'result =', t0.is_stopped ()" " = True" "test InferiorThread.is_stopped" +gdb_test "python print 'result =', t0.is_running ()" " = False" "test InferiorThread.is_running" +gdb_test "python print 'result =', t0.is_exited ()" " = False" "test InferiorThread.is_exited" |