OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /openrisc/trunk/gnu-old/gdb-7.1/gdb/testsuite/gdb.python
    from Rev 227 to Rev 816
    Reverse comparison

Rev 227 → Rev 816

/source1
0,0 → 1,19
# This testcase is part of GDB, the GNU debugger.
 
# Copyright 2008, 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 is sourced as python; pick an expression that is not valid for gdb.
print 'y%ss' % 'e'
/py-prettyprint.py
0,0 → 1,208
# Copyright (C) 2008, 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 python pretty
# printers.
 
import re
 
# Test returning a Value from a printer.
class string_print:
def __init__(self, val):
self.val = val
 
def to_string(self):
return self.val['whybother']['contents']
 
# Test a class-based printer.
class ContainerPrinter:
class _iterator:
def __init__ (self, pointer, len):
self.start = pointer
self.pointer = pointer
self.end = pointer + len
 
def __iter__(self):
return self
 
def next(self):
if self.pointer == self.end:
raise StopIteration
result = self.pointer
self.pointer = self.pointer + 1
return ('[%d]' % int (result - self.start), result.dereference())
 
def __init__(self, val):
self.val = val
 
def to_string(self):
return 'container %s with %d elements' % (self.val['name'], self.val['len'])
 
def children(self):
return self._iterator(self.val['elements'], self.val['len'])
 
class pp_s:
def __init__(self, val):
self.val = val
 
def to_string(self):
a = self.val["a"]
b = self.val["b"]
if a.address != b:
raise Exception("&a(%s) != b(%s)" % (str(a.address), str(b)))
return " a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
 
class pp_ss:
def __init__(self, val):
self.val = val
 
def to_string(self):
return "a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
 
class pp_sss:
def __init__(self, val):
self.val = val
 
def to_string(self):
return "a=<" + str(self.val['a']) + "> b=<" + str(self.val["b"]) + ">"
 
class pp_multiple_virtual:
def __init__ (self, val):
self.val = val
 
def to_string (self):
return "pp value variable is: " + str (self.val['value'])
 
class pp_vbase1:
def __init__ (self, val):
self.val = val
 
def to_string (self):
return "pp class name: " + self.val.type.tag
 
class pp_nullstr:
def __init__(self, val):
self.val = val
 
def to_string(self):
return self.val['s'].string(gdb.parameter('target-charset'))
 
class pp_ns:
"Print a std::basic_string of some kind"
 
def __init__(self, val):
self.val = val
 
def to_string(self):
len = self.val['length']
return self.val['null_str'].string (gdb.parameter ('target-charset'), length = len)
 
def display_hint (self):
return 'string'
 
class pp_ls:
"Print a std::basic_string of some kind"
 
def __init__(self, val):
self.val = val
 
def to_string(self):
return self.val['lazy_str'].lazy_string()
 
def display_hint (self):
return 'string'
 
class pp_outer:
"Print struct outer"
 
def __init__ (self, val):
self.val = val
 
def to_string (self):
return "x = %s" % self.val['x']
 
def children (self):
yield 's', self.val['s']
yield 'x', self.val['x']
 
def lookup_function (val):
"Look-up and return a pretty-printer that can print val."
 
# Get the type.
type = val.type
 
# If it points to a reference, get the reference.
if type.code == gdb.TYPE_CODE_REF:
type = type.target ()
 
# Get the unqualified type, stripped of typedefs.
type = type.unqualified ().strip_typedefs ()
 
# Get the type name.
typename = type.tag
 
if typename == None:
return None
 
# Iterate over local dictionary of types to determine
# if a printer is registered for that type. Return an
# instantiation of the printer if found.
for function in pretty_printers_dict:
if function.match (typename):
return pretty_printers_dict[function] (val)
# Cannot find a pretty printer. Return None.
 
return None
 
 
def register_pretty_printers ():
pretty_printers_dict[re.compile ('^struct s$')] = pp_s
pretty_printers_dict[re.compile ('^s$')] = pp_s
pretty_printers_dict[re.compile ('^S$')] = pp_s
 
pretty_printers_dict[re.compile ('^struct ss$')] = pp_ss
pretty_printers_dict[re.compile ('^ss$')] = pp_ss
pretty_printers_dict[re.compile ('^const S &$')] = pp_s
pretty_printers_dict[re.compile ('^SSS$')] = pp_sss
pretty_printers_dict[re.compile ('^VirtualTest$')] = pp_multiple_virtual
pretty_printers_dict[re.compile ('^Vbase1$')] = pp_vbase1
 
pretty_printers_dict[re.compile ('^struct nullstr$')] = pp_nullstr
pretty_printers_dict[re.compile ('^nullstr$')] = pp_nullstr
# Note that we purposely omit the typedef names here.
# Printer lookup is based on canonical name.
# However, we do need both tagged and untagged variants, to handle
# both the C and C++ cases.
pretty_printers_dict[re.compile ('^struct string_repr$')] = string_print
pretty_printers_dict[re.compile ('^struct container$')] = ContainerPrinter
pretty_printers_dict[re.compile ('^string_repr$')] = string_print
pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter
pretty_printers_dict[re.compile ('^struct ns$')] = pp_ns
pretty_printers_dict[re.compile ('^ns$')] = pp_ns
 
pretty_printers_dict[re.compile ('^struct lazystring$')] = pp_ls
pretty_printers_dict[re.compile ('^lazystring$')] = pp_ls
 
pretty_printers_dict[re.compile ('^struct outerstruct$')] = pp_outer
pretty_printers_dict[re.compile ('^outerstruct$')] = pp_outer
 
pretty_printers_dict = {}
 
register_pretty_printers ()
gdb.pretty_printers.append (lookup_function)
/Makefile.in
0,0 → 1,14
VPATH = @srcdir@
srcdir = @srcdir@
 
EXECUTABLES = py-type py-value py-prettyprint py-template
 
all info install-info dvi install uninstall installcheck check:
@echo "Nothing to be done for $@..."
 
clean mostlyclean:
-rm -f *~ *.o *.ci
-rm -f core $(EXECUTABLES)
 
distclean maintainer-clean realclean: clean
-rm -f Makefile config.status config.log
/py-value.c
0,0 → 1,72
/* This testcase is part of GDB, the GNU debugger.
 
Copyright 2008, 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/>. */
 
struct s
{
int a;
int b;
};
 
union u
{
int a;
float b;
};
 
enum e
{
ONE = 1,
TWO = 2
};
 
typedef struct s *PTR;
 
enum e evalue = TWO;
 
#ifdef __cplusplus
void ptr_ref(int*& rptr_int)
{
return; /* break to inspect pointer by reference. */
}
#endif
 
int
main (int argc, char *argv[])
{
char *cp = argv[0]; /* Prevent gcc from optimizing argv[] out. */
struct s s;
union u u;
PTR x = &s;
char st[17] = "divide et impera";
char nullst[17] = "divide\0et\0impera";
const char *sptr = "pointer";
const char *embed = "embedded x\201\202\203\204";
int a[3] = {1,2,3};
int *p = a;
int i = 2;
int *ptr_i = &i;
 
s.a = 3;
s.b = 5;
u.a = 7;
 
#ifdef __cplusplus
ptr_ref(ptr_i);
#endif
 
return 0; /* break to inspect struct and union */
}
py-value.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: py-cmd.exp =================================================================== --- py-cmd.exp (nonexistent) +++ py-cmd.exp (revision 816) @@ -0,0 +1,133 @@ +# 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 . + +# This file is part of the GDB testsuite. It tests the mechanism +# for defining new GDB commands in Python. + +if $tracelevel then { + strace $tracelevel +} + +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}... +# Run a test named NAME, consisting of multiple lines of input. +# After each input line INPUT, search for result line RESULT. +# Succeed if all results are seen; fail otherwise. +proc gdb_py_test_multiple {name args} { + global gdb_prompt + foreach {input result} $args { + if {[gdb_test_multiple $input "$name - $input" { + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" { + pass "$name - $input" + } + }]} { + return 1 + } + } + return 0 +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +gdb_test_multiple "python print 'hello, world!'" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + return -1 + } + -re "$gdb_prompt $" {} +} + +# Test a simple command. + +gdb_py_test_multiple "input simple command" \ + "python" "" \ + "class test_cmd (gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super (test_cmd, self).__init__ (\"test_cmd\", gdb.COMMAND_OBSCURE)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print \"test_cmd output, arg = %s\" % arg" "" \ + "test_cmd ()" "" \ + "end" "" + +gdb_test "test_cmd ugh" "test_cmd output, arg = ugh" "call simple command" + +# Test a prefix command, and a subcommand within it. + +gdb_py_test_multiple "input prefix command" \ + "python" "" \ + "class prefix_cmd (gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super (prefix_cmd, self).__init__ (\"prefix_cmd\", gdb.COMMAND_OBSCURE, gdb.COMPLETE_NONE, True)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print \"prefix_cmd output, arg = %s\" % arg" "" \ + "prefix_cmd ()" "" \ + "end" "" + +gdb_test "prefix_cmd ugh" "prefix_cmd output, arg = ugh" "call prefix command" + +gdb_py_test_multiple "input subcommand" \ + "python" "" \ + "class subcmd (gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super (subcmd, self).__init__ (\"prefix_cmd subcmd\", gdb.COMMAND_OBSCURE)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print \"subcmd output, arg = %s\" % arg" "" \ + "subcmd ()" "" \ + "end" "" + +gdb_test "prefix_cmd subcmd ugh" "subcmd output, arg = ugh" "call subcmd" + +# Test prefix command using keyword arguments. + +gdb_py_test_multiple "input prefix command, keyword arguments" \ + "python" "" \ + "class prefix_cmd2 (gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super (prefix_cmd2, self).__init__ (\"prefix_cmd2\", gdb.COMMAND_OBSCURE, prefix = True, completer_class = gdb.COMPLETE_FILENAME)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print \"prefix_cmd2 output, arg = %s\" % arg" "" \ + "prefix_cmd2 ()" "" \ + "end" "" + +gdb_test "prefix_cmd2 argh" "prefix_cmd2 output, arg = argh" "call prefix command, keyword arguments" + +gdb_py_test_multiple "input subcommand under prefix_cmd2" \ + "python" "" \ + "class subcmd (gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super (subcmd, self).__init__ (\"prefix_cmd2 subcmd\", gdb.COMMAND_OBSCURE)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print \"subcmd output, arg = %s\" % arg" "" \ + "subcmd ()" "" \ + "end" "" + +gdb_test "prefix_cmd2 subcmd ugh" "subcmd output, arg = ugh" "call subcmd under prefix_cmd2" + +# Test a subcommand in an existing GDB prefix. + +gdb_py_test_multiple "input new subcommand" \ + "python" "" \ + "class newsubcmd (gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super (newsubcmd, self).__init__ (\"info newsubcmd\", gdb.COMMAND_OBSCURE)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print \"newsubcmd output, arg = %s\" % arg" "" \ + "newsubcmd ()" "" \ + "end" "" + +gdb_test "info newsubcmd ugh" "newsubcmd output, arg = ugh" "call newsubcmd" Index: py-prettyprint.exp =================================================================== --- py-prettyprint.exp (nonexistent) +++ py-prettyprint.exp (revision 816) @@ -0,0 +1,114 @@ +# Copyright (C) 2008, 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 . + +# This file is part of the GDB testsuite. It tests Python-based +# pretty-printing for the CLI. + +if $tracelevel then { + strace $tracelevel +} + +set testfile "py-prettyprint" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +# Start with a fresh gdb. +gdb_exit +gdb_start +gdb_test_multiple "python print 'hello, world!'" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + return -1 + } + -re "$gdb_prompt $" {} +} + +# 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 } } + } +} + +proc run_lang_tests {lang} { + global srcdir subdir srcfile binfile testfile hex + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug $lang"] != "" } { + untested "Couldn't compile ${srcfile} in $lang mode" + return -1 + } + + set nl "\[\r\n\]+" + + # Start with a fresh gdb. + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} + + + if ![runto_main ] then { + perror "couldn't run to breakpoint" + return + } + + gdb_test "set print pretty on" "" + + gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \ + ".*Breakpoint.*" + gdb_test "continue" ".*Breakpoint.*" + + set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] + + gdb_test "python execfile ('${remote_python_file}')" "" + + gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" + gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>" + gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>, a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}" + + if {$lang == "c++"} { + gdb_test "print cps" "= a=<8> b=<$hex>" + gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}" + gdb_test "print cpssa\[0\]" " = {$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl}" + gdb_test "print cpssa\[1\]" " = {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl}" + gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}" + gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>" + gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>" + gdb_test "print derived" \ + " = \{.* = pp class name: Vbase1.* = \{.* = pp value variable is: 1,.*members of Vbase2:.*_vptr.Vbase2 = $hex.* = \{.*members of Vbase3.*members of Derived:.*value = 2.*" + gdb_test "print ns " "\"embedded\\\\000null\\\\000string\"" + gdb_py_test_silent_cmd "set print elements 3" "" 1 + gdb_test "print ns" "emb\.\.\.." + gdb_py_test_silent_cmd "set print elements 10" "" 1 + gdb_test "print ns" "embedded\\\\000n\.\.\.." + gdb_py_test_silent_cmd "set print elements 200" "" 1 + } + + gdb_test "print x" " = \"this is x\"" + gdb_test "print cstring" " = \"const string\"" + + gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\"" + gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" + + gdb_test "continue" "Program exited normally\." + + remote_file host delete ${remote_python_file} +} + +run_lang_tests "c" +run_lang_tests "c++" Index: py-template.cc =================================================================== --- py-template.cc (nonexistent) +++ py-template.cc (revision 816) @@ -0,0 +1,30 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008, 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 . */ + +template +struct Foo { +}; + +#ifndef TYPE +#define TYPE int +#endif + +int main() +{ + Foo foo; + return 0; // break here +} Index: py-mi.exp =================================================================== --- py-mi.exp (nonexistent) +++ py-mi.exp (revision 816) @@ -0,0 +1,242 @@ +# Copyright (C) 2008, 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 . + +# This file is part of the GDB testsuite. It tests Python-based +# pretty-printing for MI. + +load_lib mi-support.exp +set MIFLAGS "-i=mi2" + +gdb_exit +if [mi_gdb_start] { + continue +} + +set testfile "py-prettyprint" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DMI}] != "" } { + untested mi2-var-child.exp + return -1 +} + +mi_delete_breakpoints +mi_gdb_reinitialize_dir $srcdir/$subdir +mi_gdb_load ${binfile} + +if {[lsearch -exact [mi_get_features] python] < 0} { + unsupported "python support is disabled" + return -1 +} + +mi_runto main + +set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] + +mi_gdb_test "python execfile ('${remote_python_file}')" "" + +mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${testfile}.c] \ + "step to breakpoint" + +mi_create_dynamic_varobj container c \ + "create container varobj, no pretty-printing" + +mi_list_varobj_children container { + { container.name name 1 string } + { container.len len 0 int } + { container.elements elements 1 "int ." } +} "examine container children=0, no pretty-printing" + +mi_delete_varobj container "delete varobj" + +mi_gdb_test "-enable-pretty-printing" "" + +mi_create_varobj_checked string string_1 \ + "struct string_repr" \ + "create string_1 varobj" + +mi_create_varobj_checked lstring estring \ + "struct lazystring" \ + "create estring varobj" + +mi_gdb_test "-data-evaluate-expression \"string_1 = string_2\"" ".*" \ + "assign string_1 from string_2" + +mi_gdb_test "-var-update string" \ + "\\^done,changelist=\\\[{name=\"string\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}\\\]" \ + "update string varobj after assignment" + +mi_create_dynamic_varobj container c \ + "create container varobj" + +mi_list_varobj_children container { +} "examine container children=0" + +mi_next "next over update 1" + +mi_varobj_update_dynamic container "varobj update 1" { + type_changed false new_num_children 1 dynamic 1 has_more 0 +} { +} { + { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 } +} + +mi_next "next over update 2" + +mi_varobj_update_dynamic container "varobj update 2" { + type_changed false new_num_children 2 dynamic 1 has_more 0 +} { +} { + { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 } +} + +mi_gdb_test "-var-set-visualizer container None" \ + "\\^done" \ + "clear visualizer" + +mi_gdb_test "-var-update container" \ + "\\^done,changelist=\\\[\\\]" \ + "varobj update after clearing" + +mi_gdb_test "-var-set-visualizer container gdb.default_visualizer" \ + "\\^done" \ + "choose default visualizer" + +mi_varobj_update_dynamic container "varobj update after choosing default" { + type_changed false new_num_children 2 dynamic 1 has_more 0 +} { +} { + { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 } + { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 } +} + +mi_gdb_test "-var-set-visualizer container ContainerPrinter" \ + "\\^done" \ + "choose visualizer using expression" + +mi_varobj_update_dynamic container \ + "varobj update after choosing via expression" { + type_changed false new_num_children 2 dynamic 1 has_more 0 + } { + } { + { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 } + { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 } + } + +mi_list_varobj_children_range container 1 2 2 { + { {container.\[1\]} {\[1\]} 0 int } +} "list varobj children after selecting child range" + +mi_list_varobj_children_range container -1 -1 2 { + { {container.\[0\]} {\[0\]} 0 int } + { {container.\[1\]} {\[1\]} 0 int } +} "list varobj children after resetting child range" + +mi_next "next over update 3" + +mi_gdb_test "-var-set-update-range container 0 1" \ + "\\^done" \ + "set update range" + +# This should truncate the list. +mi_list_varobj_children container { + { {container.\[0\]} {\[0\]} 0 int } +} "list children after setting update range" + +# This should return just the items in [1,2). +mi_list_varobj_children_range container 1 2 2 { + { {container.\[1\]} {\[1\]} 0 int } +} "list selected children after setting range" + +# This should not be affected by the previous list-children request. +mi_list_varobj_children container { + { {container.\[0\]} {\[0\]} 0 int } +} "list children after listing selected range" + +mi_next "next over update 4" + +# This should only show the first child, because the update range has +# been set. +mi_varobj_update_dynamic container \ + "update after next with restricted range" { + type_changed false new_num_children 1 dynamic 1 has_more 1 + } { + { name {container.\[0\]} in_scope true type_changed false dynamic 1 has_more 0 } + } { + } + +mi_gdb_test "-var-set-update-range container 3 4" \ + "\\^done" \ + "set update range with non-zero start" + +# Elements were updated but should not be reported. +mi_varobj_update_dynamic container \ + "update varobj with change outside selected range" { + type_changed false new_num_children 3 dynamic 1 has_more 0 + } { + } { + } + +mi_next "next over update 5" + +# Regression test: examine an object that has no children, then update +# it to ensure that we don't print the children. +mi_create_dynamic_varobj container2 c2 \ + "create second container varobj" + +mi_gdb_test "-var-update container2" \ + "\\^done,changelist=.." \ + "update varobj, no children requested" + +mi_next "next over update 6" + +# Now container2 has an element -- and an update should mention that +# it has_more. But, because we did not request children, we still +# should not actually see them. +mi_varobj_update_dynamic container2 \ + "update varobj 2, no children requested" { + type_changed false dynamic 1 has_more 1 + } {} {} + +mi_continue_to_line \ + [gdb_get_line_number {MI outer breakpoint here} ${testfile}.c] \ + "step to outer breakpoint" + +mi_create_dynamic_varobj outer outer \ + "create outer varobj" + +mi_list_varobj_children outer { + { outer.s s 2 "struct substruct" } + { outer.x x 0 "int" } +} "list children of outer" + +mi_list_varobj_children outer.s { + { outer.s.a a 0 int } + { outer.s.b b 0 int } +} "list children of outer.s" + +mi_next "next over outer update" + +mi_gdb_test "-var-update outer" \ + ".done,changelist=.{name=\"outer.s.a\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}." \ + "update after updating element of outer" + +mi_continue_to_line \ + [gdb_get_line_number {Another MI breakpoint} ${testfile}.c] \ + "step to second breakpoint" + +mi_varobj_update_with_type_change container int 0 "update after type change" + +remote_file host delete ${remote_python_file} Index: py-type.c =================================================================== --- py-type.c (nonexistent) +++ py-type.c (revision 816) @@ -0,0 +1,56 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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 . */ + +struct s +{ + int a; + int b; +}; + +#ifdef __cplusplus +struct C +{ + int c; + int d; +}; + +struct D : C +{ + int e; + int f; +}; +#endif + +int +main () +{ + int ar[2] = {1,2}; + struct s st; +#ifdef __cplusplus + C c; + c.c = 1; + c.d = 2; + D d; + d.e = 3; + d.f = 4; +#endif + + st.a = 3; + st.b = 5; + + return 0; /* break to inspect struct and array. */ +}
py-type.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: py-template.exp =================================================================== --- py-template.exp (nonexistent) +++ py-template.exp (revision 816) @@ -0,0 +1,75 @@ +# Copyright (C) 2008, 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 . + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing values to Python. + +if $tracelevel then { + strace $tracelevel +} + +set testfile "py-template" +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \ + {debug c++}] != "" } { + untested "Couldn't compile ${srcfile}" + return -1 +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +gdb_test_multiple "python print 23" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + return -1 + } + -re "$gdb_prompt $" {} +} + +proc test_template_arg {type} { + global testfile srcdir subdir srcfile binfile + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ + executable \ + [list debug c++ additional_flags="-DTYPE=$type"]] != "" } { + untested $type + return -1 + } + gdb_load ${binfile} + if ![runto_main ] then { + perror "couldn't run to breakpoint" + return + } + # There is no executable code in main(), so we are where we want to be + gdb_test "print foo" "" + gdb_test "python foo = gdb.history(0)" "" + + # Replace '*' with '\*' in regex. + regsub -all {\*} $type {\*} t + gdb_test "python print foo.type.template_argument(0)" $t $type +} + +test_template_arg "const int" +test_template_arg "volatile int" +test_template_arg "const int &" +test_template_arg "volatile int &" +test_template_arg "volatile int * const" +test_template_arg "volatile int * const *" +test_template_arg "const int * volatile" +test_template_arg "const int * volatile * const * volatile *" Index: py-value.exp =================================================================== --- py-value.exp (nonexistent) +++ py-value.exp (revision 816) @@ -0,0 +1,426 @@ +# Copyright (C) 2008, 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 . + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing values to Python. + +if $tracelevel then { + strace $tracelevel +} + +set testfile "py-value" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile ${srcfile}" + return -1 +} + +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}... +# Run a test named NAME, consisting of multiple lines of input. +# After each input line INPUT, search for result line RESULT. +# Succeed if all results are seen; fail otherwise. +proc gdb_py_test_multiple {name args} { + global gdb_prompt + foreach {input result} $args { + if {[gdb_test_multiple $input "$name - $input" { + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" { + pass "$name - $input" + } + }]} { + return 1 + } + } + return 0 +} + +# 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 } } + } +} + +proc test_value_creation {} { + global gdb_prompt + + gdb_py_test_silent_cmd "python i = gdb.Value (True)" "create boolean value" 1 + gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create integer value" 1 + gdb_py_test_silent_cmd "python i = gdb.Value (5L)" "create long value" 1 + gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create double value" 1 + gdb_py_test_silent_cmd "python a = gdb.Value ('string test')" "create 8-bit string value" 1 + gdb_test "python print a" "\"string test\"" "print 8-bit string" + gdb_test "python print a.__class__" "" "verify type of 8-bit string" + gdb_py_test_silent_cmd "python a = gdb.Value (u'unicode test')" "create unicode value" 1 + gdb_test "python print a" "\"unicode test\"" "print Unicode string" + gdb_test "python print a.__class__" "" "verify type of unicode string" + + # Test address attribute is None in a non-addressable value + gdb_test "python print 'result =', i.address" "= None" "Test address attribute in non-addressable value" +} + +proc test_value_numeric_ops {} { + global gdb_prompt + + gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create first integer value" 0 + gdb_py_test_silent_cmd "python j = gdb.Value (2)" "create second integer value" 0 + gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create first double value" 0 + gdb_py_test_silent_cmd "python g = gdb.Value (2.5)" "create second double value" 0 + gdb_test "python print 'result = ' + str(i+j)" " = 7" "add two integer values" + gdb_test "python print (i+j).__class__" "" "verify type of integer add result" + + gdb_test "python print 'result = ' + str(f+g)" " = 3.75" "add two double values" + gdb_test "python print 'result = ' + str(i-j)" " = 3" "subtract two integer values" + gdb_test "python print 'result = ' + str(f-g)" " = -1.25" "subtract two double values" + gdb_test "python print 'result = ' + str(i*j)" " = 10" "multiply two integer values" + gdb_test "python print 'result = ' + str(f*g)" " = 3.125" "multiply two double values" + gdb_test "python print 'result = ' + str(i/j)" " = 2" "divide two integer values" + gdb_test "python print 'result = ' + str(f/g)" " = 0.5" "divide two double values" + gdb_test "python print 'result = ' + str(i%j)" " = 1" "take remainder of two integer values" + # Remainder of float is implemented in Python but not in GDB's value system. + + gdb_test "python print 'result = ' + str(i**j)" " = 25" "integer value raised to the power of another integer value" + gdb_test "python print 'result = ' + str(g**j)" " = 6.25" "double value raised to the power of integer value" + + gdb_test "python print 'result = ' + str(-i)" " = -5" "negated integer value" + gdb_test "python print 'result = ' + str(+i)" " = 5" "positive integer value" + gdb_test "python print 'result = ' + str(-f)" " = -1.25" "negated double value" + gdb_test "python print 'result = ' + str(+f)" " = 1.25" "positive double value" + gdb_test "python print 'result = ' + str(abs(j-i))" " = 3" "absolute of integer value" + gdb_test "python print 'result = ' + str(abs(f-g))" " = 1.25" "absolute of double value" + + # Test gdb.Value mixed with Python types. + + gdb_test "python print 'result = ' + str(i-1)" " = 4" "subtract integer value from python integer" + gdb_test "python print (i-1).__class__" "" "verify type of mixed integer subtraction result" + gdb_test "python print 'result = ' + str(f+1.5)" " = 2.75" "add double value with python float" + + gdb_test "python print 'result = ' + str(1-i)" " = -4" "subtract python integer from integer value" + gdb_test "python print 'result = ' + str(1.5+f)" " = 2.75" "add python float with double value" + + # Conversion test. + gdb_test "print evalue" " = TWO" + gdb_test "python evalue = gdb.history (0)" "" + gdb_test "python print int (evalue)" "2" + + # Test pointer arithmethic + + # First, obtain the pointers + gdb_test "print (void *) 2" "" "" + gdb_test "python a = gdb.history (0)" "" "" + gdb_test "print (void *) 5" "" "" + gdb_test "python b = gdb.history (0)" "" "" + + gdb_test "python print 'result = ' + str(a+5)" " = 0x7" "add pointer value with python integer" + gdb_test "python print 'result = ' + str(b-2)" " = 0x3" "subtract python integer from pointer value" + gdb_test "python print 'result = ' + str(b-a)" " = 3" "subtract two pointer values" + + # Test some invalid operations. + + gdb_test_multiple "python print 'result = ' + str(i+'foo')" "catch error in python type conversion" { + -re "Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" {pass "catch error in python type conversion"} + -re "result = .*$gdb_prompt $" {fail "catch error in python type conversion"} + -re "$gdb_prompt $" {fail "catch error in python type conversion"} + } + + gdb_test_multiple "python print 'result = ' + str(i+gdb.Value('foo'))" "catch throw of GDB error" { + -re "Traceback.*$gdb_prompt $" {pass "catch throw of GDB error"} + -re "result = .*$gdb_prompt $" {fail "catch throw of GDB error"} + -re "$gdb_prompt $" {fail "catch throw of GDB error"} + } +} + +proc test_value_boolean {} { + # First, define a useful function to test booleans. + gdb_py_test_multiple "define function to test booleans" \ + "python" "" \ + "def test_bool (val):" "" \ + " if val:" "" \ + " print 'yay'" "" \ + " else:" "" \ + " print 'nay'" "" \ + "end" "" + + gdb_test "py test_bool (gdb.Value (True))" "yay" "check evaluation of true boolean value in expression" + + gdb_test "py test_bool (gdb.Value (False))" "nay" "check evaluation of false boolean value in expression" + + gdb_test "py test_bool (gdb.Value (5))" "yay" "check evaluation of true integer value in expression" + + gdb_test "py test_bool (gdb.Value (0))" "nay" "check evaluation of false integer value in expression" + + gdb_test "py test_bool (gdb.Value (5.2))" "yay" "check evaluation of true integer value in expression" + + gdb_test "py test_bool (gdb.Value (0.0))" "nay" "check evaluation of false integer value in expression" +} + +proc test_value_compare {} { + gdb_test "py print gdb.Value (1) < gdb.Value (1)" "False" "less than, equal" + gdb_test "py print gdb.Value (1) < gdb.Value (2)" "True" "less than, less" + gdb_test "py print gdb.Value (2) < gdb.Value (1)" "False" "less than, greater" + gdb_test "py print gdb.Value (2) < None" "False" "less than, None" + + gdb_test "py print gdb.Value (1) <= gdb.Value (1)" "True" "less or equal, equal" + gdb_test "py print gdb.Value (1) <= gdb.Value (2)" "True" "less or equal, less" + gdb_test "py print gdb.Value (2) <= gdb.Value (1)" "False" "less or equal, greater" + gdb_test "py print gdb.Value (2) <= None" "False" "less or equal, None" + + gdb_test "py print gdb.Value (1) == gdb.Value (1)" "True" "equality of gdb.Values" + gdb_test "py print gdb.Value (1) == gdb.Value (2)" "False" "inequality of gdb.Values" + gdb_test "py print gdb.Value (1) == 1.0" "True" "equality of gdb.Value with Python value" + gdb_test "py print gdb.Value (1) == 2" "False" "inequality of gdb.Value with Python value" + gdb_test "py print gdb.Value (1) == None" "False" "inequality of gdb.Value with None" + + gdb_test "py print gdb.Value (1) != gdb.Value (1)" "False" "inequality, false" + gdb_test "py print gdb.Value (1) != gdb.Value (2)" "True" "inequality, true" + gdb_test "py print gdb.Value (1) != None" "True" "inequality, None" + + gdb_test "py print gdb.Value (1) > gdb.Value (1)" "False" "greater than, equal" + gdb_test "py print gdb.Value (1) > gdb.Value (2)" "False" "greater than, less" + gdb_test "py print gdb.Value (2) > gdb.Value (1)" "True" "greater than, greater" + gdb_test "py print gdb.Value (2) > None" "True" "greater than, None" + + gdb_test "py print gdb.Value (1) >= gdb.Value (1)" "True" "greater or equal, equal" + gdb_test "py print gdb.Value (1) >= gdb.Value (2)" "False" "greater or equal, less" + gdb_test "py print gdb.Value (2) >= gdb.Value (1)" "True" "greater or equal, greater" + gdb_test "py print gdb.Value (2) >= None" "True" "greater or equal, None" +} + +proc test_value_in_inferior {} { + global gdb_prompt + global testfile + + gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"] + + gdb_continue_to_breakpoint "break to inspect struct and union" + + # Just get inferior variable s in the value history, available to python. + gdb_test "print s" " = {a = 3, b = 5}" "" + + gdb_py_test_silent_cmd "python s = gdb.history (0)" "get value from history" 1 + + gdb_test "python print 'result = ' + str(s\['a'\])" " = 3" "access element inside struct using 8-bit string name" + gdb_test "python print 'result = ' + str(s\[u'a'\])" " = 3" "access element inside struct using unicode name" + + # Test dereferencing the argv pointer + + # Just get inferior variable argv the value history, available to python. + gdb_test "print argv" " = \\(char \\*\\*\\) 0x.*" "" + + gdb_py_test_silent_cmd "python argv = gdb.history (0)" "" 0 + gdb_py_test_silent_cmd "python arg0 = argv.dereference ()" "dereference value" 1 + + # Check that the dereferenced value is sane + if { ! [target_info exists noargs] } { + gdb_test "python print arg0" "0x.*$testfile\"" "verify dereferenced value" + } + + # Smoke-test is_optimized_out attribute + gdb_test "python print 'result =', arg0.is_optimized_out" "= False" "Test is_optimized_out attribute" + + # Test address attribute + gdb_test "python print 'result =', arg0.address" "= 0x\[\[:xdigit:\]\]+" "Test address attribute" + + # Test string fetches, both partial and whole. + gdb_test "print st" "\"divide et impera\"" + gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1 + gdb_test "python print st.string ()" "divide et impera" "Test string with no length" + gdb_test "python print st.string (length = -1)" "divide et impera" "Test string (length = -1) is all of the string" + gdb_test "python print st.string (length = 6)" "divide" + gdb_test "python print \"---\"+st.string (length = 0)+\"---\"" "------" "Test string (length = 0) is empty" + gdb_test "python print len(st.string (length = 0))" "0" "Test length is 0" + + + # Fetch a string that has embedded nulls. + gdb_test "print nullst" "\"divide\\\\000et\\\\000impera\".*" + gdb_py_test_silent_cmd "python nullst = gdb.history (0)" "get value from history" 1 + gdb_test "python print nullst.string ()" "divide" "Test string to first null" + # Python cannot print strings that contain the null (\0) character. + # For the purposes of this test, use repr() + gdb_py_test_silent_cmd "python nullst = nullst.string (length = 9)" "get string beyond null" 1 + gdb_test "python print repr(nullst)" "u'divide\\\\x00et'" +} + +proc test_lazy_strings {} { + + global hex + + gdb_test "print sptr" "\"pointer\"" + gdb_py_test_silent_cmd "python sptr = gdb.history (0)" "Get value from history" 1 + + gdb_py_test_silent_cmd "python lstr = sptr.lazy_string()" "Aquire lazy string" 1 + gdb_test "python print lstr.type" "const char \*." "Test type name equality" + gdb_test "python print sptr.type" "const char \*." "Test type name equality" +} + + +# A few objfile tests. +proc test_objfiles {} { + gdb_test "python\nok=False\nfor file in gdb.objfiles():\n if 'py-value' in file.filename:\n ok=True\nprint ok\nend" "True" + + gdb_test "python print gdb.objfiles()\[0\].pretty_printers" "\\\[\\\]" + + gdb_test "python gdb.objfiles()\[0\].pretty_printers = 0" \ + "pretty_printers attribute must be a list.*Error while executing Python code." +} + +proc test_value_after_death {} { + # Construct a type while the inferior is still running. + gdb_py_test_silent_cmd "python ptrtype = gdb.lookup_type('PTR')" \ + "create PTR type" 1 + + # Kill the inferior and remove the symbols. + gdb_test "kill" "" "kill the inferior" \ + "Kill the program being debugged. .y or n. $" \ + "y" + gdb_test "file" "" "Discard the symbols" \ + "Discard symbol table from.*y or n. $" \ + "y" + + # Now create a value using that type. Relies on arg0, created by + # test_value_in_inferior. + gdb_py_test_silent_cmd "python castval = arg0.cast(ptrtype.pointer())" \ + "cast arg0 to PTR" 1 + + # Make sure the type is deleted. + gdb_py_test_silent_cmd "python ptrtype = None" \ + "delete PTR type" 1 + + # Now see if the value's type is still valid. + gdb_test "python print castval.type" "PTR ." \ + "print value's type" +} + +# Regression test for invalid subscript operations. The bug was that +# the type of the value was not being checked before allowing a +# subscript operation to proceed. + +proc test_subscript_regression {lang} { + + global srcdir subdir srcfile binfile testfile hex + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug $lang"] != "" } { + untested "Couldn't compile ${srcfile} in $lang mode" + return -1 + } + + # Start with a fresh gdb. + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} + + if ![runto_main ] then { + perror "couldn't run to breakpoint" + return + } + + if {$lang == "c++"} { + gdb_breakpoint [gdb_get_line_number "break to inspect pointer by reference"] + gdb_continue_to_breakpoint "break to inspect pointer by reference" + + gdb_py_test_silent_cmd "print rptr_int" \ + "Obtain address" 1 + gdb_py_test_silent_cmd "python rptr = gdb.history(0)" \ + "Obtains value from GDB" 1 + gdb_test "python print rptr\[0\]" "2" "Check pointer passed as reference" + } + + gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"] + gdb_continue_to_breakpoint "break to inspect struct and union" + + gdb_py_test_silent_cmd "python intv = gdb.Value(1)" \ + "Create a value for subscript test" 1 + gdb_py_test_silent_cmd "python stringv = gdb.Value(\"foo\")" \ + "Create a value for subscript test" 1 + + # Try to access an int with a subscript. This should fail. + gdb_test "python print intv" "1" "Baseline print of a Python value" + gdb_test "python print intv\[0\]" "RuntimeError: Cannot subscript requested type.*" \ + "Attempt to access an integer with a subscript" + + # Try to access a string with a subscript. This should pass. + gdb_test "python print stringv" "foo." "Baseline print of a Python value" + gdb_test "python print stringv\[0\]" "f." "Attempt to access a string with a subscript" + + # Try to access an int array via a pointer with a subscript. This should pass. + gdb_py_test_silent_cmd "print p" "Build pointer to array" 1 + gdb_py_test_silent_cmd "python pointer = gdb.history(0)" "" 1 + gdb_test "python print pointer\[0\]" "1" "Access array via pointer with int subscript" + gdb_test "python print pointer\[intv\]" "2" "Access array via pointer with value subscript" + + # Try to access a single dimension array with a subscript to the + # result. This should fail. + gdb_test "python print pointer\[intv\]\[0\]" "RuntimeError: Cannot subscript requested type.*" \ + "Attempt to access an integer with a subscript" + + # Lastly, test subscript access to an array with multiple + # dimensions. This should pass. + gdb_py_test_silent_cmd "print {\"fu \",\"foo\",\"bar\"}" "Build array" 1 + gdb_py_test_silent_cmd "python marray = gdb.history(0)" "" 1 + gdb_test "python print marray\[1\]\[2\]" "o." "Test multiple subscript" +} + +# A few tests of gdb.parse_and_eval. +proc test_parse_and_eval {} { + gdb_test "python print gdb.parse_and_eval ('23')" "23" \ + "parse_and_eval constant test" + gdb_test "python print gdb.parse_and_eval ('5 + 7')" "12" \ + "parse_and_eval simple expression test" + gdb_test "python print type(gdb.parse_and_eval ('5 + 7'))" \ + ".type 'gdb.Value'."\ + "parse_and_eval type test" +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +gdb_test_multiple "python print 'hello, world!'" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + return -1 + } + -re "$gdb_prompt $" {} +} + +test_value_creation +test_value_numeric_ops +test_value_boolean +test_value_compare +test_objfiles +test_parse_and_eval + +# The following tests require execution. + +if ![runto_main] then { + fail "Can't run to main" + return 0 +} + +test_value_in_inferior +test_lazy_strings +test_value_after_death + +# The following test recompiles the binary to test either C or C++ +# values. +test_subscript_regression "c++" +test_subscript_regression "c" Index: py-frame.c =================================================================== --- py-frame.c (nonexistent) +++ py-frame.c (revision 816) @@ -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); +}
py-frame.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: py-type.exp =================================================================== --- py-type.exp (nonexistent) +++ py-type.exp (revision 816) @@ -0,0 +1,147 @@ +# 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 . + +# This file is part of the GDB testsuite. It tests the mechanism +# of exposing types to Python. + +if $tracelevel then { + strace $tracelevel +} + +set testfile "py-type" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +# Build inferior to language specification. +proc build_inferior {lang} { + global srcdir subdir srcfile binfile testfile hex + + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug $lang"] != "" } { + untested "Couldn't compile ${srcfile} in $lang mode" + return -1 + } +} + +# Restart GDB, set breakpoint and run to that breakpoint. +proc restart_gdb {bp} { + global srcdir subdir srcfile binfile testfile hex + + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} + + if ![runto_main ] then { + perror "couldn't run to breakpoint" + return + } + + gdb_breakpoint [gdb_get_line_number $bp] + gdb_continue_to_breakpoint $bp +} + + +# 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 } } + } +} + +proc test_fields {lang} { + global gdb_prompt + + if {$lang == "c++"} { + # Test usage with a class + gdb_py_test_silent_cmd "print c" "print value" 1 + gdb_py_test_silent_cmd "python c = gdb.history (0)" "get value from history" 1 + gdb_py_test_silent_cmd "python fields = c.type.fields()" "get fields" 1 + gdb_test "python print len(fields)" "2" "Check number of fields" + gdb_test "python print fields\[0\].name" "c" "Check class field c name" + gdb_test "python print fields\[1\].name" "d" "Check class field d name" + } + + # Test normal fields usage in structs. + gdb_py_test_silent_cmd "print st" "print value" 1 + gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1 + gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields" 1 + gdb_test "python print len(fields)" "2" "Check number of fields" + gdb_test "python print fields\[0\].name" "a" "Check structure field a name" + gdb_test "python print fields\[1\].name" "b" "Check structure field b name" + + # Test regression PR python/10805 + gdb_py_test_silent_cmd "print ar" "print value" 1 + gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1 + gdb_test "python fields = ar.type.fields()" + gdb_test "python print len(fields)" "1" "Check the number of fields" + gdb_test "python print fields\[0\].type" "" "Check array field type" +} + +proc test_base_class {} { + gdb_py_test_silent_cmd "print d" "print value" 1 + gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value from history" 1 + gdb_py_test_silent_cmd "python fields = d.type.fields()" "get value from history" 1 + gdb_test "python print len(fields)" "3" "Check the number of fields" + gdb_test "python print fields\[0\].is_base_class" "True" "Check base class" + gdb_test "python print fields\[1\].is_base_class" "False" "Check base class" +} + +proc test_range {} { + + # Test a valid range request. + gdb_py_test_silent_cmd "print ar" "print value" 1 + gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1 + gdb_test "python print len(ar.type.range())" "2" "Check correct tuple length" + gdb_test "python print ar.type.range()\[0\]" "0" "Check low range" + gdb_test "python print ar.type.range()\[1\]" "1" "Check high range" + + # Test a range request on a ranged type. + gdb_py_test_silent_cmd "print ar" "print value" 1 + gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1 + gdb_py_test_silent_cmd "python fields = ar.type.fields()" "get fields" 1 + gdb_test "python print fields\[0\].type.range()\[0\]" "0" "Check range type low bound" + gdb_test "python print fields\[0\].type.range()\[1\]" "1" "Check range type high bound" + + # Test where a range does not exist. + gdb_py_test_silent_cmd "print st" "print value" 1 + gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1 + gdb_test "python print st.type.range()" "RuntimeError: This type does not have a range.*" "Check range for non ranged type." +} + + +# Perform C Tests. +build_inferior "c" +restart_gdb "break to inspect struct and array." + +gdb_test_multiple "python print 'hello, world!'" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + return -1 + } + -re "$gdb_prompt $" {} +} + +test_fields "c" + +# Perform C++ Tests. +build_inferior "c++" +restart_gdb "break to inspect struct and array." +test_fields "c++" +test_base_class +test_range Index: py-function.exp =================================================================== --- py-function.exp (nonexistent) +++ py-function.exp (revision 816) @@ -0,0 +1,92 @@ +# 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 . + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing convenience functions to Python. + +if $tracelevel then { + strace $tracelevel +} + +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}... +# Run a test named NAME, consisting of multiple lines of input. +# After each input line INPUT, search for result line RESULT. +# Succeed if all results are seen; fail otherwise. +proc gdb_py_test_multiple {name args} { + global gdb_prompt + foreach {input result} $args { + if {[gdb_test_multiple $input "$name - $input" { + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" { + pass "$name - $input" + } + }]} { + return 1 + } + } + return 0 +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +gdb_test_multiple "python print 'hello, world!'" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + return -1 + } + -re "$gdb_prompt $" {} +} + +gdb_py_test_multiple "input convenience function" \ + "python" "" \ + "class test_func (gdb.Function):" "" \ + " def __init__ (self):" "" \ + " super (test_func, self).__init__ (\"test_func\")" "" \ + " def invoke (self, arg):" "" \ + " return \"test_func output, arg = %s\" % arg.string ()" "" \ + "test_func ()" "" \ + "end" "" + +gdb_test "print \$test_func (\"ugh\")" "= \"test_func output, arg = ugh\"" "call function" + +# Test returning a gdb.Value from the function. This segfaulted GDB at one point. + +gdb_py_test_multiple "input value-returning convenience function" \ + "python" "" \ + "class Double (gdb.Function):" "" \ + " def __init__ (self):" "" \ + " super (Double, self).__init__ (\"double\")" "" \ + " def invoke (self, n):" "" \ + " return n*2" "" \ + "Double ()" "" \ + "end" "" + +gdb_test "print \$double (1)" "= 2" "call value-returning function" + +gdb_py_test_multiple "input int-returning function" \ + "python" "" \ + "class Yes(gdb.Function):" "" \ + " def __init__(self):" "" \ + " gdb.Function.__init__(self, 'yes')" "" \ + " def invoke(self):" "" \ + " return 1" "" \ + "Yes ()" "" \ + "end" "" + +gdb_test "print \$yes() && \$yes()" " = 1" "call yes with &&" +gdb_test "print \$yes() || \$yes()" " = 1" "call yes with ||" Index: source2.py =================================================================== --- source2.py (nonexistent) +++ source2.py (revision 816) @@ -0,0 +1,18 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2008, 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 . + +print 'y%ss' % 'e' Index: py-prettyprint.c =================================================================== --- py-prettyprint.c (nonexistent) +++ py-prettyprint.c (revision 816) @@ -0,0 +1,253 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008, 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 . */ + +#include + +struct s +{ + int a; + int *b; +}; + +struct ss +{ + struct s a; + struct s b; +}; + +struct ns { + const char *null_str; + int length; +}; + +struct lazystring { + const char *lazy_str; +}; + +#ifdef __cplusplus +struct S : public s { + int zs; +}; + +struct SS { + int zss; + S s; +}; + +struct SSS +{ + SSS (int x, const S& r); + int a; + const S &b; +}; +SSS::SSS (int x, const S& r) : a(x), b(r) { } + +class VirtualTest +{ + private: + int value; + + public: + VirtualTest () + { + value = 1; + } +}; + +class Vbase1 : public virtual VirtualTest { }; +class Vbase2 : public virtual VirtualTest { }; +class Vbase3 : public virtual VirtualTest { }; + +class Derived : public Vbase1, public Vbase2, public Vbase3 +{ + private: + int value; + + public: + Derived () + { + value = 2; + } +}; + +#endif + +struct substruct { + int a; + int b; +}; + +struct outerstruct { + struct substruct s; + int x; +}; + +struct outerstruct +substruct_test (void) +{ + struct outerstruct outer; + outer.s.a = 0; + outer.s.b = 0; + outer.x = 0; + + outer.s.a = 3; /* MI outer breakpoint here */ + + return outer; +} + +typedef struct string_repr +{ + struct whybother + { + const char *contents; + } whybother; +} string; + +/* This lets us avoid malloc. */ +int array[100]; + +struct container +{ + string name; + int len; + int *elements; +}; + +typedef struct container zzz_type; + +string +make_string (const char *s) +{ + string result; + result.whybother.contents = s; + return result; +} + +zzz_type +make_container (const char *s) +{ + zzz_type result; + + result.name = make_string (s); + result.len = 0; + result.elements = 0; + + return result; +} + +void +add_item (zzz_type *c, int val) +{ + if (c->len == 0) + c->elements = array; + c->elements[c->len] = val; + ++c->len; +} + +void init_s(struct s *s, int a) +{ + s->a = a; + s->b = &s->a; +} + +void init_ss(struct ss *s, int a, int b) +{ + init_s(&s->a, a); + init_s(&s->b, b); +} + +void do_nothing(void) +{ + int c; + + c = 23; /* Another MI breakpoint */ +} + +struct nullstr +{ + char *s; +}; + +struct string_repr string_1 = { { "one" } }; +struct string_repr string_2 = { { "two" } }; + +int +main () +{ + struct ss ss; + struct ss ssa[2]; + string x = make_string ("this is x"); + zzz_type c = make_container ("container"); + zzz_type c2 = make_container ("container2"); + const struct string_repr cstring = { { "const string" } }; + /* Clearing by being `static' could invoke an other GDB C++ bug. */ + struct nullstr nullstr; + + + init_ss(&ss, 1, 2); + init_ss(ssa+0, 3, 4); + init_ss(ssa+1, 5, 6); + memset (&nullstr, 0, sizeof nullstr); + + struct ns ns; + ns.null_str = "embedded\0null\0string"; + ns.length = 20; + + struct lazystring estring; + estring.lazy_str = "embedded x\201\202\203\204" ; + +#ifdef __cplusplus + S cps; + + cps.zs = 7; + init_s(&cps, 8); + + SS cpss; + cpss.zss = 9; + init_s(&cpss.s, 10); + + SS cpssa[2]; + cpssa[0].zss = 11; + init_s(&cpssa[0].s, 12); + cpssa[1].zss = 13; + init_s(&cpssa[1].s, 14); + + SSS sss(15, cps); + + SSS& ref (sss); + + Derived derived; + +#endif + + add_item (&c, 23); /* MI breakpoint here */ + add_item (&c, 72); + +#ifdef MI + add_item (&c, 1011); + c.elements[0] = 1023; + c.elements[0] = 2323; + + add_item (&c2, 2222); + add_item (&c2, 3333); + + substruct_test (); + do_nothing (); +#endif + + return 0; /* break to inspect struct and union */ +}
py-prettyprint.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: py-frame.exp =================================================================== --- py-frame.exp (nonexistent) +++ py-frame.exp (revision 816) @@ -0,0 +1,88 @@ +# 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 . + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing values to Python. + +if $tracelevel then { + strace $tracelevel +} + +set testfile "py-frame" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile ${srcfile}" + return -1 +} + +# 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 } } + } +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +gdb_test_multiple "python print 'hello, world!'" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + return -1 + } + -re "$gdb_prompt $" {} +} + +# The following tests require execution. + +if ![runto_main] then { + fail "Can't run to main" + return 0 +} + +gdb_breakpoint "f2" +gdb_continue_to_breakpoint "breakpoint at f2" +gdb_test "up" "" "" + +gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0 +gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0 + +gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)" +gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)" +gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)" +gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)" +gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid" +gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name" +gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type" +gdb_test "python print 'result =', f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON" " = True" "test Frame.type" +gdb_test "python print 'result =', gdb.frame_stop_reason_string (gdb.FRAME_UNWIND_INNER_ID)" " = previous frame inner to this frame \\(corrupt stack\\?\\)" "test gdb.frame_stop_reason_string" +gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc" +gdb_test "python print 'result =', f0.older () == f1" " = True" "test Frame.older" +gdb_test "python print 'result =', f1.newer () == f0" " = True" "test Frame.newer" +gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \ + "ValueError: variable 'variable_which_surely_doesnt_exist' not found.*Error while executing Python code." \ + "test Frame.read_var - error" +gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success" + +gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame" Index: python.exp =================================================================== --- python.exp (nonexistent) +++ python.exp (revision 816) @@ -0,0 +1,82 @@ +# Copyright (C) 2008, 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 . + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing values to Python. + +if $tracelevel then { + strace $tracelevel +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +gdb_test_multiple "python print 23" "verify python support" { + -re "not supported.*$gdb_prompt $" { + unsupported "python support is disabled" + + # If Python is not supported, verify that sourcing a python script + # causes an error. + gdb_test "source $srcdir/$subdir/source2.py" "Error in sourced command file:.*" + return -1 + } + -re "$gdb_prompt $" {} +} + +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}... +# Run a test named NAME, consisting of multiple lines of input. +# After each input line INPUT, search for result line RESULT. +# Succeed if all results are seen; fail otherwise. +proc gdb_py_test_multiple {name args} { + global gdb_prompt + foreach {input result} $args { + if {[gdb_test_multiple $input "$name - $input" { + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" { + pass "$name - $input" + } + }]} { + return 1 + } + } + return 0 +} + +gdb_py_test_multiple "multi-line python command" \ + "python" "" \ + "print 23" "" \ + "end" "23" + +gdb_py_test_multiple "show python command" \ + "define zzq" "Type commands for definition of .* just \"end\"\\.*" \ + "python" "" \ + "print 23" "" \ + "end" "" \ + "end" "" \ + "show user zzq" "User command \"zzq\":.* python.*print 23.* end" + +gdb_py_test_multiple "indented multi-line python command" \ + "python" "" \ + "def foo ():" "" \ + " print 'hello, world!'" "" \ + "foo ()" "" \ + "end" "hello, world!" + +gdb_test "source $srcdir/$subdir/source2.py" "yes" + +gdb_test "python print gdb.current_objfile()" "None" +gdb_test "python print gdb.objfiles()" "\\\[\\\]"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.