From 9325cb04b5485f764cd4b92bb25d16e58c484455 Mon Sep 17 00:00:00 2001 From: Paul Koning Date: Mon, 10 Dec 2012 21:22:21 +0000 Subject: [PATCH] 2012-12-10 Paul Koning * gdb.base/charset.exp: Change print syntax for Python 3 compatibility. * gdb.python/py-block.exp: Ditto. * gdb.python/py-breakpoint.exp: Ditto. * gdb.python/py-cmd.exp: Ditto. * gdb.python/py-events.py: Ditto. * gdb.python/py-finish-breakpoint.py: Ditto. * gdb.python/py-finish-breakpoint2.exp: Ditto. * gdb.python/py-finish-breakpoint2.py: Ditto. * gdb.python/py-frame-inline.exp: Ditto. * gdb.python/py-frame.exp: Ditto. * gdb.python/py-infthread.exp: Ditto. * gdb.python/py-objfile.exp: Ditto. * gdb.python/py-parameter.exp: Ditto. * gdb.python/py-progspace.exp: Ditto. * gdb.python/py-prompt.exp: Ditto. * gdb.python/py-symbol.exp: Ditto. * gdb.python/py-symtab.exp: Ditto. * gdb.python/py-template.exp: Ditto. * gdb.python/py-value-cc.exp: Ditto. * gdb.python/python.exp: Ditto. * gdb.python/source2.py: Ditto. * gdb.python/lib-types.exp: Change print syntax for Python 3 compatibility. Use sorted() function rather than sort() method. Accept either int or long values for enum values. * gdb.python/py-events.exp: Use exec(open(...).read()) instead of execfile for Python 3 compatibility. * gdb.python/py-evsignal.exp: Ditto. * gdb.python/py-evthreads.exp: Ditto. * gdb.python/py-mi.exp: Ditto. * gdb.python/py-pp-maint.exp: Ditto. * gdb.python/py-prettyprint.exp: Ditto. * gdb.python/py-finish-breakpoint.exp: Change print syntax for Python 3 compatibility. Skip tests for Python 2.4. * gdb.python/py-inferior.exp: Change print syntax for Python 3 compatibility. Use byte string rather than character string in memory write test if Python 3. * gdb.python/py-pp-maint.py: Change class declarations to "new class" syntax. * gdb.python/py-prettyprint.py: Change iterator class to generator function for Python 3 compatibility. Make all classes "new style". Fix indentation issue and stray semicolon. * gdb.python/py-shared.expChange print syntax for Python 3 compatibility. Define "long" if Python 3. * gdb.python/py-type.exp: Change print syntax for Python 3 compatibility. Accept either int or long values for enum values. * gdb.python/py-value.exp: Change print syntax for Python 3 compatibility. Skip "long" and "unicode" tests if Python 3. Accept either "type" or "class" in type checks. * lib/gdb.exp (gdb_py_is_py3k): New flag set if Python 3. (gdb_py_is_py24): New flag set if Python 2.4 or 2.5. --- gdb/testsuite/ChangeLog | 61 +++++ gdb/testsuite/gdb.base/charset.exp | 4 +- gdb/testsuite/gdb.python/lib-types.exp | 43 ++-- gdb/testsuite/gdb.python/py-block.exp | 32 +-- gdb/testsuite/gdb.python/py-breakpoint.exp | 66 ++--- gdb/testsuite/gdb.python/py-cmd.exp | 22 +- gdb/testsuite/gdb.python/py-events.exp | 2 +- gdb/testsuite/gdb.python/py-events.py | 42 +-- gdb/testsuite/gdb.python/py-evsignal.exp | 2 +- gdb/testsuite/gdb.python/py-evthreads.exp | 2 +- .../gdb.python/py-finish-breakpoint.exp | 19 +- .../gdb.python/py-finish-breakpoint.py | 84 +++--- .../gdb.python/py-finish-breakpoint2.exp | 4 +- .../gdb.python/py-finish-breakpoint2.py | 10 +- gdb/testsuite/gdb.python/py-frame-inline.exp | 2 +- gdb/testsuite/gdb.python/py-frame.exp | 52 ++-- gdb/testsuite/gdb.python/py-inferior.exp | 69 ++--- gdb/testsuite/gdb.python/py-infthread.exp | 20 +- gdb/testsuite/gdb.python/py-mi.exp | 2 +- gdb/testsuite/gdb.python/py-objfile.exp | 6 +- gdb/testsuite/gdb.python/py-parameter.exp | 22 +- gdb/testsuite/gdb.python/py-pp-maint.exp | 2 +- gdb/testsuite/gdb.python/py-pp-maint.py | 4 +- gdb/testsuite/gdb.python/py-prettyprint.exp | 4 +- gdb/testsuite/gdb.python/py-prettyprint.py | 82 +++--- gdb/testsuite/gdb.python/py-progspace.exp | 6 +- gdb/testsuite/gdb.python/py-prompt.exp | 24 +- gdb/testsuite/gdb.python/py-shared.exp | 7 +- gdb/testsuite/gdb.python/py-symbol.exp | 86 +++---- gdb/testsuite/gdb.python/py-symtab.exp | 34 +-- gdb/testsuite/gdb.python/py-template.exp | 4 +- gdb/testsuite/gdb.python/py-type.exp | 106 ++++---- gdb/testsuite/gdb.python/py-value-cc.exp | 20 +- gdb/testsuite/gdb.python/py-value.exp | 242 +++++++++--------- gdb/testsuite/gdb.python/python.exp | 72 +++--- gdb/testsuite/gdb.python/source2.py | 2 +- gdb/testsuite/lib/gdb.exp | 25 +- 37 files changed, 684 insertions(+), 602 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 9f38c8d38a2..7bdf9634167 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,64 @@ +2012-12-10 Paul Koning + + * gdb.base/charset.exp: Change print syntax for Python 3 + compatibility. + * gdb.python/py-block.exp: Ditto. + * gdb.python/py-breakpoint.exp: Ditto. + * gdb.python/py-cmd.exp: Ditto. + * gdb.python/py-events.py: Ditto. + * gdb.python/py-finish-breakpoint.py: Ditto. + * gdb.python/py-finish-breakpoint2.exp: Ditto. + * gdb.python/py-finish-breakpoint2.py: Ditto. + * gdb.python/py-frame-inline.exp: Ditto. + * gdb.python/py-frame.exp: Ditto. + * gdb.python/py-infthread.exp: Ditto. + * gdb.python/py-objfile.exp: Ditto. + * gdb.python/py-parameter.exp: Ditto. + * gdb.python/py-progspace.exp: Ditto. + * gdb.python/py-prompt.exp: Ditto. + * gdb.python/py-symbol.exp: Ditto. + * gdb.python/py-symtab.exp: Ditto. + * gdb.python/py-template.exp: Ditto. + * gdb.python/py-value-cc.exp: Ditto. + * gdb.python/python.exp: Ditto. + * gdb.python/source2.py: Ditto. + * gdb.python/lib-types.exp: Change print syntax for Python 3 + compatibility. + Use sorted() function rather than sort() method. + Accept either int or long values for enum values. + * gdb.python/py-events.exp: Use exec(open(...).read()) instead of + execfile for Python 3 compatibility. + * gdb.python/py-evsignal.exp: Ditto. + * gdb.python/py-evthreads.exp: Ditto. + * gdb.python/py-mi.exp: Ditto. + * gdb.python/py-pp-maint.exp: Ditto. + * gdb.python/py-prettyprint.exp: Ditto. + * gdb.python/py-finish-breakpoint.exp: Change print syntax for + Python 3 compatibility. + Skip tests for Python 2.4. + * gdb.python/py-inferior.exp: Change print syntax for + Python 3 compatibility. + Use byte string rather than character string in memory write test + if Python 3. + * gdb.python/py-pp-maint.py: Change class declarations to "new + class" syntax. + * gdb.python/py-prettyprint.py: Change iterator class to generator + function for Python 3 compatibility. + Make all classes "new style". + Fix indentation issue and stray semicolon. + * gdb.python/py-shared.expChange print syntax for Python 3 + compatibility. + Define "long" if Python 3. + * gdb.python/py-type.exp: Change print syntax for Python 3 + compatibility. + Accept either int or long values for enum values. + * gdb.python/py-value.exp: Change print syntax for Python 3 + compatibility. + Skip "long" and "unicode" tests if Python 3. + Accept either "type" or "class" in type checks. + * lib/gdb.exp (gdb_py_is_py3k): New flag set if Python 3. + (gdb_py_is_py24): New flag set if Python 2.4 or 2.5. + 2012-12-10 Tom Tromey * gdb.dwarf2/implptr-64bit.exp: Run tests with two CUs as well. diff --git a/gdb/testsuite/gdb.base/charset.exp b/gdb/testsuite/gdb.base/charset.exp index 27e36d6dd06..177ffd1b49f 100644 --- a/gdb/testsuite/gdb.base/charset.exp +++ b/gdb/testsuite/gdb.base/charset.exp @@ -578,7 +578,7 @@ if {$ucs2_ok && $ucs4_ok} { if {$ucs2_ok} { set go 1 - gdb_test_multiple "python print 'hello, world!'" \ + gdb_test_multiple "python print ('hello, world!')" \ "verify python support for charset tests" { -re "not supported.*$gdb_prompt $" { unsupported "python support is disabled" @@ -591,7 +591,7 @@ if {$ucs2_ok} { gdb_test "print u\"abcdef\"" " = u\"abcdef\"" \ "set up for python printing of utf-16 string" - gdb_test "python print gdb.history(0).string()" "abcdef" \ + gdb_test "python print (gdb.history(0).string())" "abcdef" \ "extract utf-16 string using python" } } diff --git a/gdb/testsuite/gdb.python/lib-types.exp b/gdb/testsuite/gdb.python/lib-types.exp index f38ec1c3954..352b1d15ccc 100644 --- a/gdb/testsuite/gdb.python/lib-types.exp +++ b/gdb/testsuite/gdb.python/lib-types.exp @@ -37,9 +37,9 @@ gdb_test_no_output "python import gdb.types" # test get_basic_type const stripping gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')" gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)" -gdb_test "python print str (const_class1_obj.type)" "const class1" +gdb_test "python print (str (const_class1_obj.type))" "const class1" set test "const stripping" -gdb_test_multiple "python print str (basic_type_const_class1_obj)" $test { +gdb_test_multiple "python print (str (basic_type_const_class1_obj))" $test { -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { pass $test } @@ -48,9 +48,9 @@ gdb_test_multiple "python print str (basic_type_const_class1_obj)" $test { # test get_basic_type volatile stripping gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')" gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)" -gdb_test "python print str (volatile_class1_obj.type)" "volatile class1" +gdb_test "python print (str (volatile_class1_obj.type))" "volatile class1" set test "volatile stripping" -gdb_test_multiple "python print str (basic_type_volatile_class1_obj)" $test { +gdb_test_multiple "python print (str (basic_type_volatile_class1_obj))" $test { -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { pass $test } @@ -59,9 +59,9 @@ gdb_test_multiple "python print str (basic_type_volatile_class1_obj)" $test { # test get_basic_type volatile+const stripping gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')" gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)" -gdb_test "python print str (const_volatile_class1_obj.type)" "const volatile class1" +gdb_test "python print (str (const_volatile_class1_obj.type))" "const volatile class1" set test "volatile+const stripping" -gdb_test_multiple "python print str (basic_type_const_volatile_class1_obj)" $test { +gdb_test_multiple "python print (str (basic_type_const_volatile_class1_obj))" $test { -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { pass $test } @@ -70,9 +70,9 @@ gdb_test_multiple "python print str (basic_type_const_volatile_class1_obj)" $tes # test get_basic_type typedef stripping gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')" gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)" -gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1" +gdb_test "python print (str (typedef_class1_obj.type))" "typedef_class1" set test "typedef stripping" -gdb_test_multiple "python print str (basic_type_typedef_class1_obj)" $test { +gdb_test_multiple "python print (str (basic_type_typedef_class1_obj))" $test { -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { pass $test } @@ -81,9 +81,9 @@ gdb_test_multiple "python print str (basic_type_typedef_class1_obj)" $test { # test get_basic_type reference stripping gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')" gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)" -gdb_test "python print str (class1_ref_obj.type)" "class1 &" +gdb_test "python print (str (class1_ref_obj.type))" "class1 &" set test "reference stripping" -gdb_test_multiple "python print str (basic_type_class1_ref_obj)" $test { +gdb_test_multiple "python print (str (basic_type_class1_ref_obj))" $test { -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { pass $test } @@ -92,9 +92,9 @@ gdb_test_multiple "python print str (basic_type_class1_ref_obj)" $test { # test nested typedef stripping gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')" gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)" -gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1" +gdb_test "python print (str (typedef_class1_obj.type))" "typedef_class1" set test "nested typedef stripping" -gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_obj)" $test { +gdb_test_multiple "python print (str (basic_type_typedef_const_typedef_class1_obj))" $test { -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { pass $test } @@ -103,9 +103,9 @@ gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_obj # test nested typedef/reference stripping gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')" gdb_test_no_output "python basic_type_typedef_const_typedef_class1_ref_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_ref_obj.type)" -gdb_test "python print str (typedef_const_typedef_class1_ref_obj.type)" "const typedef_const_typedef_class1_ref" +gdb_test "python print (str (typedef_const_typedef_class1_ref_obj.type))" "const typedef_const_typedef_class1_ref" set test "nested typedef/ref stripping" -gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_ref_obj)" $test { +gdb_test_multiple "python print (str (basic_type_typedef_const_typedef_class1_ref_obj))" $test { -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { pass $test } @@ -113,21 +113,20 @@ gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_ref # test has_field on simple class gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')" -gdb_test "python print gdb.types.has_field (class1_obj.type, 'x')" "True" -gdb_test "python print gdb.types.has_field (class1_obj.type, 'nope')" "False" +gdb_test "python print (gdb.types.has_field (class1_obj.type, 'x'))" "True" +gdb_test "python print (gdb.types.has_field (class1_obj.type, 'nope'))" "False" # test has_field in base class gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')" -gdb_test "python print gdb.types.has_field (subclass1_obj.type, 'x')" "True" +gdb_test "python print (gdb.types.has_field (subclass1_obj.type, 'x'))" "True" # test make_enum_dict gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')" gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)" -gdb_test_no_output "python enum1_list = enum1_dict.items ()" -gdb_test_no_output "python enum1_list.sort ()" -gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]} +gdb_test_no_output "python enum1_list = sorted (enum1_dict.items ())" +gdb_test "python print (enum1_list)" {\[\('A', 0L?\), \('B', 1L?\), \('C', 2L?\)\]} # test deep_items gdb_test_no_output "python struct_a = gdb.lookup_type ('struct A')" -gdb_test "python print struct_a.keys ()" {\['a', '', 'c', ''\]} -gdb_test "python print \[k for k,v in gdb.types.deep_items(struct_a)\]" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]} +gdb_test "python print (struct_a.keys ())" {\['a', '', 'c', ''\]} +gdb_test "python print (\[k for k,v in gdb.types.deep_items(struct_a)\])" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]} diff --git a/gdb/testsuite/gdb.python/py-block.exp b/gdb/testsuite/gdb.python/py-block.exp index 745f84468d2..239cc0061be 100644 --- a/gdb/testsuite/gdb.python/py-block.exp +++ b/gdb/testsuite/gdb.python/py-block.exp @@ -39,35 +39,35 @@ gdb_continue_to_breakpoint "Block break here." # Test initial innermost block. gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0 -gdb_test "python print block" "" "Check block not None" -gdb_test "python print block.function" "None" "First anonymous block" -gdb_test "python print block.start" "${decimal}" "Check start not None" -gdb_test "python print block.end" "${decimal}" "Check end not None" +gdb_test "python print (block)" "" "Check block not None" +gdb_test "python print (block.function)" "None" "First anonymous block" +gdb_test "python print (block.start)" "${decimal}" "Check start not None" +gdb_test "python print (block.end)" "${decimal}" "Check end not None" # Test global/static blocks gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0 -gdb_test "python print block.is_global" "False" "Not a global block" -gdb_test "python print block.is_static" "False" "Not a static block" +gdb_test "python print (block.is_global)" "False" "Not a global block" +gdb_test "python print (block.is_static)" "False" "Not a static block" gdb_py_test_silent_cmd "python gblock = block.global_block" "Get block" 1 gdb_py_test_silent_cmd "python sblock = block.static_block" "Get block" 1 -gdb_test "python print gblock.is_global" "True" "Is the global block" -gdb_test "python print sblock.is_static" "True" "Is the static block" +gdb_test "python print (gblock.is_global)" "True" "Is the global block" +gdb_test "python print (sblock.is_static)" "True" "Is the static block" # Move up superblock(s) until we reach function block_func. gdb_test_no_output "python block = block.superblock" "Get superblock" -gdb_test "python print block.function" "None" "Second anonymous block" +gdb_test "python print (block.function)" "None" "Second anonymous block" gdb_test_no_output "python block = block.superblock" "Get superblock 2" -gdb_test "python print block.function" "block_func" \ +gdb_test "python print (block.function)" "block_func" \ "Print superblock 2 function" # Switch frames, then test for main block. gdb_test "up" ".*" gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0 gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0 -gdb_test "python print block" "" \ +gdb_test "python print (block)" "" \ "Check Frame 2's block not None" -gdb_test "python print block.function" "main" "main block" +gdb_test "python print (block.function)" "main" "main block" # Test Block is_valid. This must always be the last test in this @@ -76,12 +76,12 @@ delete_breakpoints gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame block" 0 gdb_py_test_silent_cmd "python block_iter = iter (block)" "Get Frame block" 0 -gdb_test "python print block.is_valid()" "True" \ +gdb_test "python print (block.is_valid())" "True" \ "Check block validity" -gdb_test "python print block_iter.is_valid()" "True" \ +gdb_test "python print (block_iter.is_valid())" "True" \ "Check block validity" gdb_unload -gdb_test "python print block.is_valid()" "False" \ +gdb_test "python print (block.is_valid())" "False" \ "Check block validity" -gdb_test "python print block_iter.is_valid()" "False" \ +gdb_test "python print (block_iter.is_valid())" "False" \ "Check block validity" diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index 9bedeb2fca4..3f225f7ee43 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -37,8 +37,8 @@ global hex decimal # Initially there should be one breakpoint: main. gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print blist\[0\]" "" "Check obj exists" -gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" +gdb_test "python print (blist\[0\])" "" "Check obj exists" +gdb_test "python print (blist\[0\].location)" "main." "Check breakpoint location" set mult_line [gdb_get_line_number "Break at multiply."] gdb_breakpoint ${mult_line} @@ -47,25 +47,25 @@ gdb_continue_to_breakpoint "Break at multiply." # Check that the Python breakpoint code noted the addition of a # breakpoint "behind the scenes". gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print len(blist)" "2" "Check for two breakpoints" -gdb_test "python print blist\[0\]" "" "Check obj exists" -gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" -gdb_test "python print blist\[1\]" "" "Check obj exists" +gdb_test "python print (len(blist))" "2" "Check for two breakpoints" +gdb_test "python print (blist\[0\])" "" "Check obj exists" +gdb_test "python print (blist\[0\].location)" "main." "Check breakpoint location" +gdb_test "python print (blist\[1\])" "" "Check obj exists" -gdb_test "python print blist\[1\].location" "py-breakpoint\.c:${mult_line}*" \ +gdb_test "python print (blist\[1\].location)" "py-breakpoint\.c:${mult_line}*" \ "Check breakpoint location" # Check hit and ignore counts. -gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count" +gdb_test "python print (blist\[1\].hit_count)" "1" "Check breakpoint hit count" gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0 gdb_continue_to_breakpoint "Break at multiply." -gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count" +gdb_test "python print (blist\[1\].hit_count)" "6" "Check breakpoint hit count" gdb_test "print result" " = 545" "Check expected variable result after 6 iterations" # Test breakpoint is enabled and disabled correctly.. gdb_breakpoint [gdb_get_line_number "Break at add."] gdb_continue_to_breakpoint "Break at add." -gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled." +gdb_test "python print (blist\[1\].enabled)" "True" "Check breakpoint enabled." gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0 gdb_continue_to_breakpoint "Break at add." gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0 @@ -73,11 +73,11 @@ gdb_continue_to_breakpoint "Break at multiply." # Test other getters and setters. gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread" -gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type" -gdb_test "python print blist\[0\].number" "1" "Check breakpoint number" -gdb_test "python print blist\[1\].number" "2" "Check breakpoint number" -gdb_test "python print blist\[2\].number" "3" "Check breakpoint number" +gdb_test "python print (blist\[1\].thread)" "None" "Check breakpoint thread" +gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" "True" "Check breakpoint type" +gdb_test "python print (blist\[0\].number)" "1" "Check breakpoint number" +gdb_test "python print (blist\[1\].number)" "2" "Check breakpoint number" +gdb_test "python print (blist\[2\].number)" "3" "Check breakpoint number" # Start with a fresh gdb. clean_restart ${testfile} @@ -93,12 +93,12 @@ set end_location [gdb_get_line_number "Break at end."] gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" "Set breakpoint" 0 gdb_breakpoint [gdb_get_line_number "Break at end."] gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print len(del_list)" "3" "Number of breakpoints before delete" +gdb_test "python print (len(del_list))" "3" "Number of breakpoints before delete" gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$deltst_location.*" gdb_py_test_silent_cmd "python dp1.delete()" "Delete Breakpoint" 0 -gdb_test "python print dp1.number" "RuntimeError: Breakpoint 2 is invalid.*" "Check breakpoint invalidated" +gdb_test "python print (dp1.number)" "RuntimeError: Breakpoint 2 is invalid.*" "Check breakpoint invalidated" gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print len(del_list)" "2" "Number of breakpoints after delete" +gdb_test "python print (len(del_list))" "2" "Number of breakpoints after delete" gdb_continue_to_breakpoint "Break at end." ".*/$srcfile:$end_location.*" @@ -115,11 +115,11 @@ set bp_location1 [gdb_get_line_number "Break at multiply."] gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0 gdb_continue_to_breakpoint "Break at multiply." gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0 -gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set" +gdb_test "python print (bp1.condition)" "i == 5" "Test conditional has been set" gdb_continue_to_breakpoint "Break at multiply." gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations" gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0 -gdb_test "python print bp1.condition" "None" "Test conditional read" +gdb_test "python print (bp1.condition)" "None" "Test conditional read" gdb_continue_to_breakpoint "Break at multiply." gdb_test "print i" "6" "Test breakpoint stopped after six iterations" @@ -134,7 +134,7 @@ gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } gdb_test "end" gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result" +gdb_test "python print (blist\[len(blist)-1\].commands)" "print \"Command for breakpoint has been executed.\".*print result" # Start with a fresh gdb. clean_restart ${testfile} @@ -149,16 +149,16 @@ delete_breakpoints set ibp_location [gdb_get_line_number "Break at multiply."] gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" "Set invisible breakpoint" 0 gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print ilist\[0\]" "" "Check invisible bp obj exists" -gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" -gdb_test "python print ilist\[0\].visible" "True" "Check breakpoint visibility" +gdb_test "python print (ilist\[0\])" "" "Check invisible bp obj exists" +gdb_test "python print (ilist\[0\].location)" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" +gdb_test "python print (ilist\[0\].visible)" "True" "Check breakpoint visibility" gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check info breakpoints shows visible breakpoints" delete_breakpoints gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" "Set invisible breakpoint" 0 gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 -gdb_test "python print ilist\[0\]" "" "Check invisible bp obj exists" -gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" -gdb_test "python print ilist\[0\].visible" "False" "Check breakpoint visibility" +gdb_test "python print (ilist\[0\])" "" "Check invisible bp obj exists" +gdb_test "python print (ilist\[0\].location)" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" +gdb_test "python print (ilist\[0\].visible)" "False" "Check breakpoint visibility" gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" gdb_test "maint info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check maint info breakpoints shows invisible breakpoints" @@ -251,10 +251,10 @@ gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" "Set breakpoint" 0 gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$bp_location2.*" gdb_test "print i" "3" "Check inferior value matches python accounting" -gdb_test "python print eval_bp1.inf_i" "3" "Check python accounting matches inferior" -gdb_test "python print also_eval_bp1.count" "4" \ +gdb_test "python print (eval_bp1.inf_i)" "3" "Check python accounting matches inferior" +gdb_test "python print (also_eval_bp1.count)" "4" \ "Check non firing same-location breakpoint eval function was also called at each stop." -gdb_test "python print eval_bp1.count" "4" \ +gdb_test "python print (eval_bp1.count)" "4" \ "Check non firing same-location breakpoint eval function was also called at each stop." delete_breakpoints @@ -279,10 +279,10 @@ gdb_test "python eval_bp2.stop = stop_func" \ delete_breakpoints gdb_breakpoint [gdb_get_line_number "Break at multiply."] gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" "Set breakpoint" 0 -gdb_test "python print check_eval.count" "0" \ +gdb_test "python print (check_eval.count)" "0" \ "Test that evaluate function has not been yet executed (ie count = 0)" gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$bp_location2.*" -gdb_test "python print check_eval.count" "1" \ +gdb_test "python print (check_eval.count)" "1" \ "Test that evaluate function is run when location also has normal bp" gdb_py_test_multiple "Sub-class a watchpoint" \ @@ -298,5 +298,5 @@ gdb_py_test_multiple "Sub-class a watchpoint" \ delete_breakpoints gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" "Set watchpoint" 0 gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" "Test watchpoint write" -gdb_test "python print never_eval_bp1.count" "0" \ +gdb_test "python print (never_eval_bp1.count)" "0" \ "Check that this unrelated breakpoints eval function was never called." diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp index 36fa343d891..3b8032b056d 100644 --- a/gdb/testsuite/gdb.python/py-cmd.exp +++ b/gdb/testsuite/gdb.python/py-cmd.exp @@ -35,7 +35,7 @@ gdb_py_test_multiple "input simple 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" "" \ + " print (\"test_cmd output, arg = %s\" % arg)" "" \ "test_cmd ()" "" \ "end" "" @@ -49,7 +49,7 @@ gdb_py_test_multiple "input prefix 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" "" \ + " print (\"prefix_cmd output, arg = %s\" % arg)" "" \ "prefix_cmd ()" "" \ "end" "" @@ -61,7 +61,7 @@ gdb_py_test_multiple "input subcommand" \ " 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" "" \ + " print (\"subcmd output, arg = %s\" % arg)" "" \ "subcmd ()" "" \ "end" "" @@ -75,7 +75,7 @@ gdb_py_test_multiple "input prefix command, keyword arguments" \ " 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" "" \ + " print (\"prefix_cmd2 output, arg = %s\" % arg)" "" \ "prefix_cmd2 ()" "" \ "end" "" @@ -87,7 +87,7 @@ gdb_py_test_multiple "input subcommand under prefix_cmd2" \ " 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" "" \ + " print (\"subcmd output, arg = %s\" % arg)" "" \ "subcmd ()" "" \ "end" "" @@ -101,7 +101,7 @@ gdb_py_test_multiple "input new subcommand" \ " def __init__ (self):" "" \ " super (newsubcmd, self).__init__ (\"info newsubcmd\", gdb.COMMAND_OBSCURE)" "" \ " def invoke (self, arg, from_tty):" "" \ - " print \"newsubcmd output, arg = %s\" % arg" "" \ + " print (\"newsubcmd output, arg = %s\" % arg)" "" \ "newsubcmd ()" "" \ "end" "" @@ -123,19 +123,19 @@ gdb_test "test_error_cmd ugh" "you lose!" "call error command" # Test gdb.string_to_argv. -gdb_test "python print gdb.string_to_argv (\"1 2 3\")" \ +gdb_test "python print (gdb.string_to_argv (\"1 2 3\"))" \ {\['1', '2', '3'\]} \ "string_to_argv (\"1 2 3\")" -gdb_test "python print gdb.string_to_argv (\"'1 2' 3\")" \ +gdb_test "python print (gdb.string_to_argv (\"'1 2' 3\"))" \ {\['1 2', '3'\]} \ "string_to_argv (\"'1 2' 3\")" -gdb_test "python print gdb.string_to_argv ('\"1 2\" 3')" \ +gdb_test "python print (gdb.string_to_argv ('\"1 2\" 3'))" \ {\['1 2', '3'\]} \ "string_to_argv ('\"1 2\" 3')" -gdb_test "python print gdb.string_to_argv ('1\\ 2 3')" \ +gdb_test "python print (gdb.string_to_argv ('1\\ 2 3'))" \ {\['1 2', '3'\]} \ "string_to_argv ('1\\ 2 3')" @@ -147,7 +147,7 @@ gdb_py_test_multiple "input simple user-defined command" \ " def __init__ (self):" "" \ " super (test_help, self).__init__ (\"test_help\", gdb.COMMAND_USER)" "" \ " def invoke (self, arg, from_tty):" "" \ - " print \"test_cmd output, arg = %s\" % arg" "" \ + " print (\"test_cmd output, arg = %s\" % arg)" "" \ "test_help ()" "" \ "end" "" diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index 6b655bbb57d..3e96527bd8c 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -43,7 +43,7 @@ clean_restart ${testfile} if { [skip_python_tests] } { continue } -gdb_test_no_output "python execfile ('${pyfile}')" "" +gdb_test_no_output "python exec (open ('${pyfile}').read ())" "" gdb_test "Test_Newobj_Events" "New ObjectFile Event tester registered." "Register new objfile event handler" diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py index f7e45f56bcf..4a3ff8004f9 100644 --- a/gdb/testsuite/gdb.python/py-events.py +++ b/gdb/testsuite/gdb.python/py-events.py @@ -19,46 +19,46 @@ import gdb def signal_stop_handler (event): if (isinstance (event, gdb.StopEvent)): - print "event type: stop" + print ("event type: stop") if (isinstance (event, gdb.SignalEvent)): - print "stop reason: signal" - print "stop signal: %s" % (event.stop_signal) + print ("stop reason: signal") + print ("stop signal: %s" % (event.stop_signal)) if ( event.inferior_thread is not None) : - print "thread num: %s" % (event.inferior_thread.num); + print ("thread num: %s" % (event.inferior_thread.num)) def breakpoint_stop_handler (event): if (isinstance (event, gdb.StopEvent)): - print "event type: stop" + print ("event type: stop") if (isinstance (event, gdb.BreakpointEvent)): - print "stop reason: breakpoint" - print "first breakpoint number: %s" % (event.breakpoint.number) + print ("stop reason: breakpoint") + print ("first breakpoint number: %s" % (event.breakpoint.number)) for bp in event.breakpoints: - print "breakpoint number: %s" % (bp.number) + print ("breakpoint number: %s" % (bp.number)) if ( event.inferior_thread is not None) : - print "thread num: %s" % (event.inferior_thread.num); + print ("thread num: %s" % (event.inferior_thread.num)) else: - print "all threads stopped" + print ("all threads stopped") def exit_handler (event): if (isinstance (event, gdb.ExitedEvent)): - print "event type: exit" - print "exit code: %d" % (event.exit_code) - print "exit inf: %d" % (event.inferior.num) - print "dir ok: %s" % str('exit_code' in dir(event)) + print ("event type: exit") + print ("exit code: %d" % (event.exit_code)) + print ("exit inf: %d" % (event.inferior.num)) + print ("dir ok: %s" % str('exit_code' in dir(event))) def continue_handler (event): if (isinstance (event, gdb.ContinueEvent)): - print "event type: continue" + print ("event type: continue") if ( event.inferior_thread is not None) : - print "thread num: %s" % (event.inferior_thread.num); + print ("thread num: %s" % (event.inferior_thread.num)) def new_objfile_handler (event): if (isinstance (event, gdb.NewObjFileEvent)): - print "event type: new_objfile" + print ("event type: new_objfile") if (event.new_objfile is not None): - print "new objfile name: %s" % (event.new_objfile.filename) + print ("new objfile name: %s" % (event.new_objfile.filename)) else: - print "new objfile is None" + print ("new objfile is None") class test_events (gdb.Command): """Test events.""" @@ -71,7 +71,7 @@ class test_events (gdb.Command): gdb.events.stop.connect (breakpoint_stop_handler) gdb.events.exited.connect (exit_handler) gdb.events.cont.connect (continue_handler) - print "Event testers registered." + print ("Event testers registered.") test_events () @@ -83,6 +83,6 @@ class test_newobj_events (gdb.Command): def invoke (self, arg, from_tty): gdb.events.new_objfile.connect (new_objfile_handler) - print "New ObjectFile Event tester registered." + print ("New ObjectFile Event tester registered.") test_newobj_events () diff --git a/gdb/testsuite/gdb.python/py-evsignal.exp b/gdb/testsuite/gdb.python/py-evsignal.exp index b3c1d66defd..b92b063ce39 100644 --- a/gdb/testsuite/gdb.python/py-evsignal.exp +++ b/gdb/testsuite/gdb.python/py-evsignal.exp @@ -31,7 +31,7 @@ clean_restart $testfile if { [skip_python_tests] } { continue } -gdb_test_no_output "python execfile ('${pyfile}')" "" +gdb_test_no_output "python exec (open ('${pyfile}').read ())" "" gdb_test "Test_Events" "Event testers registered." gdb_test_no_output "set non-stop on" diff --git a/gdb/testsuite/gdb.python/py-evthreads.exp b/gdb/testsuite/gdb.python/py-evthreads.exp index 98f25015abc..6efa9385fac 100644 --- a/gdb/testsuite/gdb.python/py-evthreads.exp +++ b/gdb/testsuite/gdb.python/py-evthreads.exp @@ -36,7 +36,7 @@ clean_restart $testfile if { [skip_python_tests] } { continue } -gdb_test_no_output "python execfile ('${pyfile}')" "" +gdb_test_no_output "python exec (open ('${pyfile}').read ())" "" gdb_test "Test_Events" "Event testers registered." gdb_test_no_output "set non-stop on" diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp index d521021918e..9b1e1b61ccb 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp @@ -23,6 +23,13 @@ if {[skip_shlib_tests]} { load_lib gdb-python.exp +if { $gdb_py_is_py24 == 1 } { + # Python 2.4, 2.5 do not support the "ValueError as e" syntax used in + # the py-finish-breakpoint.py script. + untested py-finish-breakpoint.exp + return 0 +} + set libfile "py-events-shlib" set libsrc $srcdir/$subdir/$libfile.c set lib_sl [standard_output_file $libfile-nodebug.so] @@ -74,17 +81,17 @@ gdb_test "python finishbp_default = gdb.FinishBreakpoint ()" \ "Temporary breakpoint.*" "set FinishBreakpoint with default frame value" gdb_test "python finishbp = MyFinishBreakpoint (gdb.parse_and_eval ('a'), gdb.newest_frame ())" \ "Temporary breakpoint.*" "set FinishBreakpoint" -gdb_test "python print finishbp.return_value" "None.*" \ +gdb_test "python print (finishbp.return_value)" "None.*" \ "check return_value at init" # check normal bp hit gdb_test "continue" "MyFinishBreakpoint stop with.*return_value is: -5.*#0.*increase.*" \ "check MyFinishBreakpoint hit" -gdb_test "python print finishbp.return_value" "-5.*" "check return_value" +gdb_test "python print (finishbp.return_value)" "-5.*" "check return_value" -gdb_test "python print finishbp_default.hit_count" "1.*" "check finishBP on default frame has been hit" -gdb_test "python print finishbp.is_valid()" "False.*"\ +gdb_test "python print (finishbp_default.hit_count)" "1.*" "check finishBP on default frame has been hit" +gdb_test "python print (finishbp.is_valid())" "False.*"\ "ensure that finish bp is invalid afer normal hit" # check FinishBreakpoint in main no allowed @@ -119,7 +126,7 @@ gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \ "SimpleFinishBreakpoint init" \ "set finish breakpoint" gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit" -gdb_test "python print finishBP.return_value" "None" "check return value without debug symbol" +gdb_test "python print (finishBP.return_value)" "None" "check return value without debug symbol" # # Test FinishBreakpoint in function returned by longjmp @@ -143,7 +150,7 @@ gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \ "set BP after the jump" gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \ "check FinishBP out of scope notification" -gdb_test "python print finishbp.is_valid()" "False.*"\ +gdb_test "python print (finishbp.is_valid())" "False.*"\ "ensure that finish bp is invalid afer out of scope notification" # diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint.py b/gdb/testsuite/gdb.python/py-finish-breakpoint.py index 2878bb82fd8..3f9744d0f86 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint.py +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint.py @@ -15,75 +15,75 @@ # This file is part of the GDB testsuite. It tests python Finish # Breakpoints. - + class MyFinishBreakpoint (gdb.FinishBreakpoint): - def __init__(self, val, frame): - gdb.FinishBreakpoint.__init__ (self, frame) - print "MyFinishBreakpoint init" - self.val = val - - def stop(self): - print "MyFinishBreakpoint stop with %d" % int (self.val.dereference ()) - print "return_value is: %d" % int (self.return_value) - gdb.execute ("where 1") - return True - - def out_of_scope(self): - print "MyFinishBreakpoint out of scope" + def __init__(self, val, frame): + gdb.FinishBreakpoint.__init__ (self, frame) + print ("MyFinishBreakpoint init") + self.val = val + + def stop(self): + print ("MyFinishBreakpoint stop with %d" % int (self.val.dereference ())) + print ("return_value is: %d" % int (self.return_value)) + gdb.execute ("where 1") + return True + + def out_of_scope(self): + print ("MyFinishBreakpoint out of scope") class TestBreakpoint(gdb.Breakpoint): def __init__(self): gdb.Breakpoint.__init__ (self, spec="test_1", internal=1) self.silent = True self.count = 0 - print "TestBreakpoint init" + print ("TestBreakpoint init") def stop(self): - self.count += 1 - try: - TestFinishBreakpoint (gdb.newest_frame (), self.count) + self.count += 1 + try: + TestFinishBreakpoint (gdb.newest_frame (), self.count) except ValueError as e: - print e + print (e) return False class TestFinishBreakpoint (gdb.FinishBreakpoint): def __init__ (self, frame, count): - self.count = count + self.count = count gdb.FinishBreakpoint.__init__ (self, frame, internal=1) def stop(self): - print "-->", self.number + print ("-->", self.number) if (self.count == 3): - print "test stop: %d" % self.count + print ("test stop: %d" % self.count) return True else: - print "test don't stop: %d" % self.count + print ("test don't stop: %d" % self.count) return False def out_of_scope(self): - print "test didn't finish: %d" % self.count + print ("test didn't finish: %d" % self.count) class TestExplicitBreakpoint(gdb.Breakpoint): - def stop(self): - try: - SimpleFinishBreakpoint (gdb.newest_frame ()) - except ValueError as e: - print e - return False + def stop(self): + try: + SimpleFinishBreakpoint (gdb.newest_frame ()) + except ValueError as e: + print (e) + return False class SimpleFinishBreakpoint(gdb.FinishBreakpoint): - def __init__(self, frame): - gdb.FinishBreakpoint.__init__ (self, frame) - - print "SimpleFinishBreakpoint init" - - def stop(self): - print "SimpleFinishBreakpoint stop" - return True - - def out_of_scope(self): - print "SimpleFinishBreakpoint out of scope" + def __init__(self, frame): + gdb.FinishBreakpoint.__init__ (self, frame) + + print ("SimpleFinishBreakpoint init") + + def stop(self): + print ("SimpleFinishBreakpoint stop" ) + return True + + def out_of_scope(self): + print ("SimpleFinishBreakpoint out of scope") -print "Python script imported" +print ("Python script imported") diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp index 3b08ef8c21c..60151f6fba1 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp @@ -45,10 +45,10 @@ gdb_test "source $pyfile" ".*Python script imported.*" \ gdb_breakpoint "throw_exception_1" gdb_test "continue" "Breakpoint .*throw_exception_1.*" "run to exception 1" -gdb_test "python print len(gdb.breakpoints())" "3" "check BP count" +gdb_test "python print (len(gdb.breakpoints()))" "3" "check BP count" gdb_test "python ExceptionFinishBreakpoint(gdb.newest_frame())" "init ExceptionFinishBreakpoint" "set FinishBP after the exception" gdb_test "continue" ".*stopped at ExceptionFinishBreakpoint.*" "check FinishBreakpoint in catch()" -gdb_test "python print len(gdb.breakpoints())" "3" "check finish BP removal" +gdb_test "python print (len(gdb.breakpoints()))" "3" "check finish BP removal" gdb_test "continue" ".*Breakpoint.* throw_exception_1.*" "continue to second exception" gdb_test "python ExceptionFinishBreakpoint(gdb.newest_frame())" "init ExceptionFinishBreakpoint" "set FinishBP after the exception" diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint2.py b/gdb/testsuite/gdb.python/py-finish-breakpoint2.py index 984e77fc3e5..73869e0b3f8 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint2.py +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint2.py @@ -19,15 +19,15 @@ class ExceptionFinishBreakpoint(gdb.FinishBreakpoint): def __init__(self, frame): gdb.FinishBreakpoint.__init__ (self, frame, internal=1) - self.silent = True; - print "init ExceptionFinishBreakpoint" + self.silent = True + print ("init ExceptionFinishBreakpoint") def stop(self): - print "stopped at ExceptionFinishBreakpoint" + print ("stopped at ExceptionFinishBreakpoint") return True def out_of_scope(self): - print "exception did not finish ..." + print ("exception did not finish ...") -print "Python script imported" +print ("Python script imported") diff --git a/gdb/testsuite/gdb.python/py-frame-inline.exp b/gdb/testsuite/gdb.python/py-frame-inline.exp index 49fa87e0928..7d57b3a5cf6 100644 --- a/gdb/testsuite/gdb.python/py-frame-inline.exp +++ b/gdb/testsuite/gdb.python/py-frame-inline.exp @@ -36,4 +36,4 @@ gdb_test "info frame" "inlined into frame 1\r\n.*" gdb_test "up" "#1 g .*" -gdb_test "python print gdb.selected_frame().read_var('l')" "\r\n42" +gdb_test "python print (gdb.selected_frame().read_var('l'))" "\r\n42" diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp index 993e77479fb..ccee3034ebf 100644 --- a/gdb/testsuite/gdb.python/py-frame.exp +++ b/gdb/testsuite/gdb.python/py-frame.exp @@ -39,24 +39,24 @@ gdb_continue_to_breakpoint "Block break here." gdb_py_test_silent_cmd "python bf1 = gdb.selected_frame ()" "get frame" 0 # First test that read_var is unaffected by PR 11036 changes. -gdb_test "python print bf1.read_var(\"i\")" "\"stuff\"" "test i" -gdb_test "python print bf1.read_var(\"f\")" "\"foo\"" "test f" -gdb_test "python print bf1.read_var(\"b\")" "\"bar\"" "test b" +gdb_test "python print (bf1.read_var(\"i\"))" "\"stuff\"" "test i" +gdb_test "python print (bf1.read_var(\"f\"))" "\"foo\"" "test f" +gdb_test "python print (bf1.read_var(\"b\"))" "\"bar\"" "test b" # Test the read_var function in another block other than the current # block (in this case, the super block). Test thar read_var is reading # the correct variables of i and f but they are the correct value and type. gdb_py_test_silent_cmd "python sb = bf1.block().superblock" "get superblock" 0 -gdb_test "python print bf1.read_var(\"i\", sb)" "1.1.*" "test i = 1.1" -gdb_test "python print bf1.read_var(\"i\", sb).type" "double" "test double i" -gdb_test "python print bf1.read_var(\"f\", sb)" "2.2.*" "test f = 2.2" -gdb_test "python print bf1.read_var(\"f\", sb).type" "double" "test double f" +gdb_test "python print (bf1.read_var(\"i\", sb))" "1.1.*" "test i = 1.1" +gdb_test "python print (bf1.read_var(\"i\", sb).type)" "double" "test double i" +gdb_test "python print (bf1.read_var(\"f\", sb))" "2.2.*" "test f = 2.2" +gdb_test "python print (bf1.read_var(\"f\", sb).type)" "double" "test double f" # And again test another outerblock, this time testing "i" is the # correct value and type. gdb_py_test_silent_cmd "python sb = sb.superblock" "get superblock" 0 -gdb_test "python print bf1.read_var(\"i\", sb)" "99" "test i = 99" -gdb_test "python print bf1.read_var(\"i\", sb).type" "int" "test int i" +gdb_test "python print (bf1.read_var(\"i\", sb))" "99" "test i = 99" +gdb_test "python print (bf1.read_var(\"i\", sb).type)" "int" "test int i" gdb_breakpoint "f2" gdb_continue_to_breakpoint "breakpoint at f2" @@ -67,26 +67,26 @@ 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 f1 == gdb.newest_frame()" False \ +gdb_test "python print (f1 == gdb.newest_frame())" False \ "selected frame -vs- newest frame" -gdb_test "python print bframe == gdb.newest_frame()" True \ +gdb_test "python print (bframe == gdb.newest_frame())" True \ "newest frame -vs- newest frame" -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')" \ +gdb_test "python print ('result = %s' % (f0 == f1))" " = False" "test equality comparison (false)" +gdb_test "python print ('result = %s' % (f0 == f0))" " = True" "test equality comparison (true)" +gdb_test "python print ('result = %s' % (f0 != f1))" " = True" "test inequality comparison (true)" +gdb_test "python print ('result = %s' % (f0 != f0))" " = False" "test inequality comparison (false)" +gdb_test "python print ('result = %s' % f0.is_valid ())" " = True" "test Frame.is_valid" +gdb_test "python print ('result = %s' % f0.name ())" " = f2" "test Frame.name" +gdb_test "python print ('result = %s' % (f0.type () == gdb.NORMAL_FRAME))" " = True" "test Frame.type" +gdb_test "python print ('result = %s' % (f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON))" " = True" "test Frame.type" +gdb_test "python print ('result = %s' % 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 = %s' % f0.pc ())" " = \[0-9\]+" "test Frame.pc" +gdb_test "python print ('result = %s' % (f0.older () == f1))" " = True" "test Frame.older" +gdb_test "python print ('result = %s' % (f1.newer () == f0))" " = True" "test Frame.newer" +gdb_test "python print ('result = %s' % 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 = %s' % f0.read_var ('a'))" " = 1" "test Frame.read_var - success" -gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame" +gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame" diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 15e684aa226..85dfd905cec 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -51,20 +51,20 @@ if ![runto_main] then { # 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" "\\(,\\)" "verify inferiors list" +gdb_test "python print (inferiors)" "\\(,\\)" "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 ()" "\\(,\\)" "test Inferior.threads" +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 ())" "\\(,\\)" "test Inferior.threads" # Test the number of inferior threads. gdb_breakpoint check_threads gdb_continue_to_breakpoint "cont to check_threads" ".*pthread_barrier_wait.*" -gdb_test "python print len (i0.threads ())" "\r\n9" "test Inferior.threads 2" +gdb_test "python print (len (i0.threads ()))" "\r\n9" "test Inferior.threads 2" # Proceed to the next test. @@ -75,12 +75,17 @@ gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*" 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)" \ +gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \ "read str contents" 1 -gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0 +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 gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \ "write str" 1 -gdb_test "print str" " = \"hallo, testsuite\"" \ +gdb_test "print (str)" " = \"hallo, testsuite\"" \ "ensure str was changed in the inferior" # Test memory search. @@ -99,18 +104,18 @@ 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')" \ +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')" \ +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')" \ +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. @@ -124,7 +129,7 @@ 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)" \ +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. @@ -135,7 +140,7 @@ 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)" \ +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. @@ -146,7 +151,7 @@ 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)" \ +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. @@ -160,11 +165,11 @@ 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)" \ +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)" \ +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)" \ +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 @@ -179,13 +184,13 @@ 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 "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 "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" +gdb_test "py print (third)" "${pattern_not_found}" "search spanning large range 3rd result" # For native targets, test a pattern straddling a chunk boundary. @@ -193,7 +198,7 @@ if [isnative] { 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)" \ + gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern))" \ "${one_pattern_found}" "find pattern straddling chunk boundary" } @@ -201,28 +206,28 @@ if [isnative] { # this testcase as it kills the inferior. 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" -gdb_test "python print inf_list\[0\].is_valid()" "True" \ +gdb_test "python print (len(inf_list))" "1" "Get inferior list length" +gdb_test "python print (inf_list\[0\].is_valid())" "True" \ "Check inferior validity" 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" -gdb_test "python print inf_list\[0\].is_valid()" "True" \ +gdb_test "python print (len(inf_list))" "2" "Get inferior list length" +gdb_test "python print (inf_list\[0\].is_valid())" "True" \ "Check inferior validity" -gdb_test "python print inf_list\[1\].is_valid()" "True" \ +gdb_test "python print (inf_list\[1\].is_valid())" "True" \ "Check inferior validity" gdb_test_no_output "remove-inferiors 2" "remove-inferiors 3" -gdb_test "python print inf_list\[0\].is_valid()" "False" \ +gdb_test "python print (inf_list\[0\].is_valid())" "False" \ "Check inferior validity" -gdb_test "python print inf_list\[1\].is_valid()" "True" \ +gdb_test "python print (inf_list\[1\].is_valid())" "True" \ "Check inferior validity" # Test gdb.selected_inferior() gdb_test "inferior 1" ".*" "Switch to first inferior" -gdb_test "py print gdb.selected_inferior().num" "1" "First inferior selected" +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 "py print (gdb.selected_inferior().num)" "3" "Third inferior selected" gdb_test "inferior 1" ".*" "Switch to first inferior" gdb_test_no_output "remove-inferiors 3" "Remove second inferior" diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp index 0ddc912492b..fbd7e49b76b 100644 --- a/gdb/testsuite/gdb.python/py-infthread.exp +++ b/gdb/testsuite/gdb.python/py-infthread.exp @@ -40,28 +40,28 @@ if ![runto_main] then { # 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" "\\" "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 (t0)" "\\" "verify InferiorThread object" +gdb_test "python print ('result = %s' % t0.num)" " = \[0-9\]+" "test Inferior.num" +gdb_test "python print ('result = %s' % str (t0.ptid))" " = \\(\[0-9\]+, \[0-9\]+, \[0-9\]+\\)" "test InferiorThread.ptid" gdb_py_test_silent_cmd "python name = gdb.selected_thread().name" \ "get supplied name of current thread" 1 gdb_py_test_silent_cmd "python gdb.selected_thread().name = 'hibob'" \ "set name of current thread" 1 -gdb_test "python print gdb.selected_thread().name" "hibob" \ +gdb_test "python print (gdb.selected_thread().name)" "hibob" \ "check name of current thread" gdb_py_test_silent_cmd "python gdb.selected_thread().name = None" \ "reset name of current thread" 1 -gdb_test "python print gdb.selected_thread().name == name" "True" \ +gdb_test "python print (gdb.selected_thread().name == name)" "True" \ "check name of current thread again" -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" +gdb_test "python print ('result = %s' % t0.is_stopped ())" " = True" "test InferiorThread.is_stopped" +gdb_test "python print ('result = %s' % t0.is_running ())" " = False" "test InferiorThread.is_running" +gdb_test "python print ('result = %s' % t0.is_exited ())" " = False" "test InferiorThread.is_exited" # Test InferiorThread is_valid. This must always be the last test in # this testcase as it kills the inferior. -gdb_test "python print 'result =', t0.is_valid ()" " = True" "test InferiorThread.is_valid" +gdb_test "python print ('result = %s' % t0.is_valid ())" " = True" "test InferiorThread.is_valid" gdb_test_no_output "kill inferior 1" "kill inferior 1" -gdb_test "python print 'result =', t0.is_valid ()" " = False" "test InferiorThread.is_valid" +gdb_test "python print ('result = %s' % t0.is_valid ())" " = False" "test InferiorThread.is_valid" diff --git a/gdb/testsuite/gdb.python/py-mi.exp b/gdb/testsuite/gdb.python/py-mi.exp index 49b4def7d3a..17975fac028 100644 --- a/gdb/testsuite/gdb.python/py-mi.exp +++ b/gdb/testsuite/gdb.python/py-mi.exp @@ -44,7 +44,7 @@ mi_runto main set remote_python_file [remote_download host ${srcdir}/${subdir}/${pyfile}] -mi_gdb_test "python execfile ('${remote_python_file}')" "" +mi_gdb_test "python exec (open ('${remote_python_file}').read ())" "" mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${srcfile}] \ "step to breakpoint" diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index cbd0f87c336..e8a863adcee 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -37,10 +37,10 @@ gdb_py_test_silent_cmd "python sym = gdb.lookup_symbol(\"some_var\")" \ gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \ "Get backing object file" 1 -gdb_test "python print objfile.filename" ".*py-objfile.*" \ +gdb_test "python print (objfile.filename)" ".*py-objfile.*" \ "Get objfile validity" -gdb_test "python print objfile.is_valid()" "True" \ +gdb_test "python print (objfile.is_valid())" "True" \ "Get objfile validity" gdb_unload -gdb_test "python print objfile.is_valid()" "False" \ +gdb_test "python print (objfile.is_valid())" "False" \ "Get objfile validity after unload" diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp index 08538ead464..7af990894a9 100644 --- a/gdb/testsuite/gdb.python/py-parameter.exp +++ b/gdb/testsuite/gdb.python/py-parameter.exp @@ -27,7 +27,7 @@ gdb_reinitialize_dir $srcdir/$subdir if { [skip_python_tests] } { continue } # We use "." here instead of ":" so that this works on win32 too. -gdb_test "python print gdb.parameter ('directories')" "$srcdir/$subdir.\\\$cdir.\\\$cwd" +gdb_test "python print (gdb.parameter ('directories'))" "$srcdir/$subdir.\\\$cdir.\\\$cwd" # Test a simple boolean parameter. gdb_py_test_multiple "Simple gdb booleanparameter" \ @@ -49,11 +49,11 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \ "test_param = TestParam ('print test-param')" ""\ "end" -gdb_test "python print test_param.value" "True" "Test parameter value" +gdb_test "python print (test_param.value)" "True" "Test parameter value" gdb_test "show print test-param" "The state of the Test Parameter is on.*" "Show parameter on" gdb_test "set print test-param off" "Test Parameter has been set to off" "Turn off parameter" gdb_test "show print test-param" "The state of the Test Parameter is off.*" "Show parameter off" -gdb_test "python print test_param.value" "False" "Test parameter value" +gdb_test "python print (test_param.value)" "False" "Test parameter value" gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "Test show help" gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "Test set help" gdb_test "help set print" "set print test-param -- Set the state of the boolean test-param.*" "Test general help" @@ -76,11 +76,11 @@ gdb_py_test_multiple "enum gdb parameter" \ "test_enum_param = TestEnumParam ('print test-enum-param')" ""\ "end" -gdb_test "python print test_enum_param.value" "one" "Test enum parameter value" +gdb_test "python print (test_enum_param.value)" "one" "Test enum parameter value" gdb_test "show print test-enum-param" "The state of the enum is one.*" "Show parameter is initial value" gdb_test "set print test-enum-param two" "The state of the enum has been set to two" "Set enum to two" gdb_test "show print test-enum-param" "The state of the enum is two.*" "Show parameter is new value" -gdb_test "python print test_enum_param.value" "two" "Test enum parameter value" +gdb_test "python print (test_enum_param.value)" "two" "Test enum parameter value" gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter" # Test a file parameter. @@ -100,11 +100,11 @@ gdb_py_test_multiple "file gdb parameter" \ "test_file_param = TestFileParam ('test-file-param')" ""\ "end" -gdb_test "python print test_file_param.value" "foo.txt" "Test file parameter value" +gdb_test "python print (test_file_param.value)" "foo.txt" "Test file parameter value" gdb_test "show test-file-param" "The name of the file is foo.txt.*" "Show initial file value" gdb_test "set test-file-param bar.txt" "The name of the file has been changed to bar.txt" "Set new file parameter" 1 gdb_test "show test-file-param" "The name of the file is bar.txt.*" "Show new file value" -gdb_test "python print test_file_param.value" "bar.txt" "Test new file parameter value" +gdb_test "python print (test_file_param.value)" "bar.txt" "Test new file parameter value" gdb_test "set test-file-param" "Argument required.*" # Test a parameter that is not documented. @@ -127,7 +127,7 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \ gdb_test "show print test-undoc-param" "The state of the Test Parameter is on.*" "Show parameter on" gdb_test "set print test-undoc-param off" "Test Parameter has been set to off" "Turn off parameter" gdb_test "show print test-undoc-param" "The state of the Test Parameter is off.*" "Show parameter off" -gdb_test "python print test_undoc_param.value" "False" "Test parameter value" +gdb_test "python print (test_undoc_param.value)" "False" "Test parameter value" gdb_test "help show print test-undoc-param" "This command is not documented.*" "Test show help" gdb_test "help set print test-undoc-param" "This command is not documented.*" "Test set help" gdb_test "help set print" "set print test-undoc-param -- This command is not documented.*" "Test general help" @@ -145,7 +145,7 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \ gdb_test "show print test-nodoc-param" "This command is not documented.*" "Show parameter on" gdb_test "set print test-nodoc-param off" "This command is not documented.*" "Turn off parameter" gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "Show parameter off" -gdb_test "python print test_nodoc_param.value" "False" "Test parameter value" +gdb_test "python print (test_nodoc_param.value)" "False" "Test parameter value" gdb_test "help show print test-nodoc-param" "This command is not documented.*" "Test show help" gdb_test "help set print test-nodoc-param" "This command is not documented.*" "Test set help" gdb_test "help set print" "set print test-nodoc-param -- This command is not documented.*" "Test general help" @@ -163,11 +163,11 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \ "test_param = TestParam ('print test-param')" ""\ "end" -gdb_test "python print test_param.value" "True" "Test parameter value" +gdb_test "python print (test_param.value)" "True" "Test parameter value" gdb_test "show print test-param" "State of the Test Parameter on.*" "Show parameter on" gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "Turn off parameter" gdb_test "show print test-param" "State of the Test Parameter off.*" "Show parameter off" -gdb_test "python print test_param.value" "False" "Test parameter value" +gdb_test "python print (test_param.value)" "False" "Test parameter value" gdb_test "help show print test-param" "State of the Test Parameter.*" "Test show help" gdb_test "help set print test-param" "Set the state of the Test Parameter.*" "Test set help" gdb_test "help set print" "set print test-param -- Set the state of the Test Parameter.*" "Test general help" diff --git a/gdb/testsuite/gdb.python/py-pp-maint.exp b/gdb/testsuite/gdb.python/py-pp-maint.exp index 3f08ba12a79..e0119c41075 100644 --- a/gdb/testsuite/gdb.python/py-pp-maint.exp +++ b/gdb/testsuite/gdb.python/py-pp-maint.exp @@ -43,7 +43,7 @@ gdb_test "continue" ".*Breakpoint.*" set python_file ${srcdir}/${subdir}/${testfile}.py -gdb_test_no_output "python execfile ('${python_file}')" "" +gdb_test_no_output "python exec (open ('${python_file}').read ())" "" gdb_test "info pretty-printer" \ {.*function_lookup_test.*pp-test.*struct ss.*} diff --git a/gdb/testsuite/gdb.python/py-pp-maint.py b/gdb/testsuite/gdb.python/py-pp-maint.py index 1677371b902..397869c431e 100644 --- a/gdb/testsuite/gdb.python/py-pp-maint.py +++ b/gdb/testsuite/gdb.python/py-pp-maint.py @@ -37,7 +37,7 @@ def lookup_function_lookup_test(val): return None -class pp_s: +class pp_s (object): def __init__(self, val): self.val = val @@ -49,7 +49,7 @@ class pp_s: return "a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">" -class pp_ss: +class pp_ss (object): def __init__(self, val): self.val = val diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp index 22af83c5905..4207d7c2f78 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp @@ -55,7 +55,7 @@ proc run_lang_tests {exefile lang} { set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] - gdb_test_no_output "python execfile ('${remote_python_file}')" + gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" 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>>" @@ -125,7 +125,7 @@ if ![runto_main ] then { set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python execfile ('${remote_python_file}')" +gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" gdb_breakpoint [gdb_get_line_number "eval-break"] gdb_continue_to_breakpoint "eval-break" ".* eval-break .*" diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py index 65a7cabc886..227046e10ef 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.py +++ b/gdb/testsuite/gdb.python/py-prettyprint.py @@ -19,8 +19,17 @@ import re import gdb +def _iterator (pointer, len): + start = pointer + end = pointer + len + while pointer != end: + if exception_flag: + raise gdb.MemoryError ('hi bob') + yield ('[%d]' % int (pointer - start), pointer.dereference()) + pointer += 1 + # Test returning a Value from a printer. -class string_print: +class string_print (object): def __init__(self, val): self.val = val @@ -28,22 +37,7 @@ class string_print: 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()) +class ContainerPrinter (object): def __init__(self, val): self.val = val @@ -52,7 +46,7 @@ class ContainerPrinter: return 'container %s with %d elements' % (self.val['name'], self.val['len']) def children(self): - return self._iterator(self.val['elements'], self.val['len']) + return _iterator(self.val['elements'], self.val['len']) # Treats a container as array. class ArrayPrinter: @@ -88,25 +82,7 @@ class ArrayPrinter: exception_flag = False # Test a printer where to_string is None -class NoStringContainerPrinter: - 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 - if exception_flag: - raise gdb.MemoryError, 'hi bob' - result = self.pointer - self.pointer = self.pointer + 1 - return ('[%d]' % int (result - self.start), result.dereference()) - +class NoStringContainerPrinter (object): def __init__(self, val): self.val = val @@ -114,9 +90,9 @@ class NoStringContainerPrinter: return None def children(self): - return self._iterator(self.val['elements'], self.val['len']) + return _iterator(self.val['elements'], self.val['len']) -class pp_s: +class pp_s (object): def __init__(self, val): self.val = val @@ -127,42 +103,42 @@ class pp_s: 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: +class pp_ss (object): 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: +class pp_sss (object): 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: +class pp_multiple_virtual (object): def __init__ (self, val): self.val = val def to_string (self): return "pp value variable is: " + str (self.val['value']) -class pp_vbase1: +class pp_vbase1 (object): def __init__ (self, val): self.val = val def to_string (self): return "pp class name: " + self.val.type.tag -class pp_nullstr: +class pp_nullstr (object): def __init__(self, val): self.val = val def to_string(self): return self.val['s'].string(gdb.target_charset()) -class pp_ns: +class pp_ns (object): "Print a std::basic_string of some kind" def __init__(self, val): @@ -177,7 +153,7 @@ class pp_ns: pp_ls_encoding = None -class pp_ls: +class pp_ls (object): "Print a std::basic_string of some kind" def __init__(self, val): @@ -192,7 +168,7 @@ class pp_ls: def display_hint (self): return 'string' -class pp_hint_error: +class pp_hint_error (object): "Throw error from display_hint" def __init__(self, val): @@ -204,7 +180,7 @@ class pp_hint_error: def display_hint (self): raise Exception("hint failed") -class pp_children_as_list: +class pp_children_as_list (object): "Throw error from display_hint" def __init__(self, val): @@ -216,7 +192,7 @@ class pp_children_as_list: def children (self): return [('one', 1)] -class pp_outer: +class pp_outer (object): "Print struct outer" def __init__ (self, val): @@ -229,24 +205,24 @@ class pp_outer: yield 's', self.val['s'] yield 'x', self.val['x'] -class MemoryErrorString: +class MemoryErrorString (object): "Raise an error" def __init__(self, val): self.val = val def to_string(self): - raise gdb.MemoryError ("Cannot access memory."); + raise gdb.MemoryError ("Cannot access memory.") def display_hint (self): return 'string' -class pp_eval_type: +class pp_eval_type (object): def __init__(self, val): self.val = val def to_string(self): - gdb.execute("bt", to_string=True) + gdb.execute("bt", to_string=True) return "eval=<" + str(gdb.parse_and_eval("eval_func (123456789, 2, 3, 4, 5, 6, 7, 8)")) + ">" def lookup_function (val): diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index ee7ce9e51fd..54addbdc15c 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -31,11 +31,11 @@ gdb_reinitialize_dir $srcdir/$subdir # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } -gdb_test "python print gdb.current_progspace().filename" "None" \ +gdb_test "python print (gdb.current_progspace().filename)" "None" \ "current progspace filename (None)" -gdb_test "python print gdb.progspaces()" "\\\[\\\]" +gdb_test "python print (gdb.progspaces())" "\\\[\\\]" gdb_load ${binfile} -gdb_test "python print gdb.current_progspace().filename" "py-progspace" \ +gdb_test "python print (gdb.current_progspace().filename)" "py-progspace" \ "current progspace filename (py-progspace)" diff --git a/gdb/testsuite/gdb.python/py-prompt.exp b/gdb/testsuite/gdb.python/py-prompt.exp index b5d9368d0d5..4fe623873c3 100644 --- a/gdb/testsuite/gdb.python/py-prompt.exp +++ b/gdb/testsuite/gdb.python/py-prompt.exp @@ -59,24 +59,24 @@ set gdb_prompt "\[(\]Foo\[)\]" set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing on\""] prompt_gdb_start -gdb_test "python x = len(p); print gdb.execute(\"show prompt\", to_string = True)" \ +gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \ ".*prompt is \"$gdb_prompt \".*" \ "show prompt gets the correct result" -gdb_test "python print x, len(p)" "1 2" \ +gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ "retrieving the prompt causes no extra prompt_hook calls" -gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \ +gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ "prompt_hook argument is default prompt." gdb_exit set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing off\""] prompt_gdb_start -gdb_test "python x = len(p); print gdb.execute(\"show prompt\", to_string = True)" \ +gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \ ".*prompt is \"$gdb_prompt \".*" \ "show prompt gets the correct result 2" -gdb_test "python print x, len(p)" "1 2" \ +gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ "retrieving the prompt causes no extra prompt_hook calls 2" -gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \ +gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ "prompt_hook argument is default prompt. 2" gdb_exit @@ -98,12 +98,12 @@ set GDBFLAGS [concat $GDBFLAGS " -ex \"continue&\""] # sync_execution = 1 is_running = 1 prompt_gdb_start -gdb_test "python x = len(p); print gdb.execute(\"show prompt\", to_string = True)" \ +gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \ ".*prompt is \"$gdb_prompt \".*" \ "show prompt gets the correct result 3" -gdb_test "python print x, len(p)" "1 2" \ +gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ "retrieving the prompt causes no extra prompt_hook calls 3" -gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \ +gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ "prompt_hook argument is default prompt. 3" gdb_exit @@ -115,12 +115,12 @@ set GDBFLAGS [concat $GDBFLAGS " -ex \"interrupt\""] # sync_execution = 1 is_running = 0 prompt_gdb_start -gdb_test "python x = len(p); print gdb.execute(\"show prompt\", to_string = True)" \ +gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \ ".*prompt is \"$gdb_prompt \".*" \ "show prompt gets the correct result 4" -gdb_test "python print x, len(p)" "1 2" \ +gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ "retrieving the prompt causes no extra prompt_hook calls 4" -gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \ +gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ "prompt_hook argument is default prompt. 4" gdb_exit diff --git a/gdb/testsuite/gdb.python/py-shared.exp b/gdb/testsuite/gdb.python/py-shared.exp index 454a325260e..0dcdd090987 100644 --- a/gdb/testsuite/gdb.python/py-shared.exp +++ b/gdb/testsuite/gdb.python/py-shared.exp @@ -58,8 +58,11 @@ runto [gdb_get_line_number "Break to end."] # Test gdb.solib_name gdb_test "p &func1" "" "func1 address" gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1 -gdb_test "python print gdb.solib_name(long(func1))" "py-shared-sl.sl" "test func1 solib location" +if { $gdb_py_is_py3k == 1 } { + gdb_py_test_silent_cmd "python long = int" "" 0 +} +gdb_test "python print (gdb.solib_name(long(func1)))" "py-shared-sl.sl" "test func1 solib location" gdb_test "p &main" "" "main address" gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1 -gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location" +gdb_test "python print (gdb.solib_name(long(main)))" "None" "test main solib location" diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp index 4442e79c050..865451ad148 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -31,20 +31,20 @@ if { [skip_python_tests] } { continue } # point where we don't have a current frame, and we don't want to # require one. gdb_py_test_silent_cmd "python main_func = gdb.lookup_global_symbol(\"main\")" "Lookup main" 1 -gdb_test "python print main_func.is_function" "True" "Test main_func.is_function" -gdb_test "python print gdb.lookup_global_symbol(\"junk\")" "None" "Test lookup_global_symbol(\"junk\")" +gdb_test "python print (main_func.is_function)" "True" "Test main_func.is_function" +gdb_test "python print (gdb.lookup_global_symbol(\"junk\"))" "None" "Test lookup_global_symbol(\"junk\")" -gdb_test "python print gdb.lookup_global_symbol('main').value()" "$hex .main." \ +gdb_test "python print (gdb.lookup_global_symbol('main').value())" "$hex .main." \ "print value of main" set qq_line [gdb_get_line_number "line of qq"] -gdb_test "python print gdb.lookup_global_symbol('qq').line" "$qq_line" \ +gdb_test "python print (gdb.lookup_global_symbol('qq').line)" "$qq_line" \ "print line number of qq" -gdb_test "python print gdb.lookup_global_symbol('qq').value()" "72" \ +gdb_test "python print (gdb.lookup_global_symbol('qq').value())" "72" \ "print value of qq" -gdb_test "python print gdb.lookup_global_symbol('qq').needs_frame" \ +gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \ "False" \ "print whether qq needs a frame" @@ -63,21 +63,21 @@ gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0 # Test is_argument attribute. gdb_py_test_silent_cmd "python arg = gdb.lookup_symbol(\"arg\")" "Get variable a" 0 -gdb_test "python print arg\[0\].is_variable" "False" "Test arg.is_variable" -gdb_test "python print arg\[0\].is_constant" "False" "Test arg.is_constant" -gdb_test "python print arg\[0\].is_argument" "True" "Test arg.is_argument" -gdb_test "python print arg\[0\].is_function" "False" "Test arg.is_function" +gdb_test "python print (arg\[0\].is_variable)" "False" "Test arg.is_variable" +gdb_test "python print (arg\[0\].is_constant)" "False" "Test arg.is_constant" +gdb_test "python print (arg\[0\].is_argument)" "True" "Test arg.is_argument" +gdb_test "python print (arg\[0\].is_function)" "False" "Test arg.is_function" # Test is_function attribute. gdb_py_test_silent_cmd "python func = frame.block().function" "Get block" 0 -gdb_test "python print func.is_variable" "False" "Test func.is_variable" -gdb_test "python print func.is_constant" "False" "Test func.is_constant" -gdb_test "python print func.is_argument" "False" "Test func.is_argument" -gdb_test "python print func.is_function" "True" "Test func.is_function" -gdb_test "python print func.name" "func" "Test func.name" -gdb_test "python print func.print_name" "func" "Test func.print_name" -gdb_test "python print func.linkage_name" "func" "Test func.linkage_name" -gdb_test "python print func.addr_class == gdb.SYMBOL_LOC_BLOCK" "True" "Test func.addr_class" +gdb_test "python print (func.is_variable)" "False" "Test func.is_variable" +gdb_test "python print (func.is_constant)" "False" "Test func.is_constant" +gdb_test "python print (func.is_argument)" "False" "Test func.is_argument" +gdb_test "python print (func.is_function)" "True" "Test func.is_function" +gdb_test "python print (func.name)" "func" "Test func.name" +gdb_test "python print (func.print_name)" "func" "Test func.print_name" +gdb_test "python print (func.linkage_name)" "func" "Test func.linkage_name" +gdb_test "python print (func.addr_class == gdb.SYMBOL_LOC_BLOCK)" "True" "Test func.addr_class" gdb_breakpoint [gdb_get_line_number "Break at end."] gdb_continue_to_breakpoint "Break at end." @@ -85,33 +85,33 @@ gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 # Test is_variable attribute. gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0 -gdb_test "python print a\[0\].is_variable" "True" "Test a.is_variable" -gdb_test "python print a\[0\].is_constant" "False" "Test a.is_constant" -gdb_test "python print a\[0\].is_argument" "False" "Test a.is_argument" -gdb_test "python print a\[0\].is_function" "False" "Test a.is_function" -gdb_test "python print a\[0\].addr_class == gdb.SYMBOL_LOC_COMPUTED" "True" "Test a.addr_class" +gdb_test "python print (a\[0\].is_variable)" "True" "Test a.is_variable" +gdb_test "python print (a\[0\].is_constant)" "False" "Test a.is_constant" +gdb_test "python print (a\[0\].is_argument)" "False" "Test a.is_argument" +gdb_test "python print (a\[0\].is_function)" "False" "Test a.is_function" +gdb_test "python print (a\[0\].addr_class == gdb.SYMBOL_LOC_COMPUTED)" "True" "Test a.addr_class" -gdb_test "python print a\[0\].value()" \ +gdb_test "python print (a\[0\].value())" \ "symbol requires a frame to compute its value.*"\ "try to print value of a without a frame" -gdb_test "python print a\[0\].value(frame)" "0" \ +gdb_test "python print (a\[0\].value(frame))" "0" \ "print value of a" -gdb_test "python print a\[0\].needs_frame" "True" \ +gdb_test "python print (a\[0\].needs_frame)" "True" \ "print whether a needs a frame" # Test is_constant attribute gdb_py_test_silent_cmd "python t = gdb.lookup_symbol(\"one\")" "Get variable a" 0 -gdb_test "python print t\[0\].is_variable" "False" "Test t.is_variable" -gdb_test "python print t\[0\].is_constant" "True" "Test t.is_constant" -gdb_test "python print t\[0\].is_argument" "False" "Test t.is_argument" -gdb_test "python print t\[0\].is_function" "False" "Test t.is_function" -gdb_test "python print t\[0\].addr_class == gdb.SYMBOL_LOC_CONST" "True" "Test t.addr_class" +gdb_test "python print (t\[0\].is_variable)" "False" "Test t.is_variable" +gdb_test "python print (t\[0\].is_constant)" "True" "Test t.is_constant" +gdb_test "python print (t\[0\].is_argument)" "False" "Test t.is_argument" +gdb_test "python print (t\[0\].is_function)" "False" "Test t.is_function" +gdb_test "python print (t\[0\].addr_class == gdb.SYMBOL_LOC_CONST)" "True" "Test t.addr_class" # Test type attribute. -gdb_test "python print t\[0\].type" "enum tag" "Get type" +gdb_test "python print (t\[0\].type)" "enum tag" "Get type" # Test symtab attribute. -gdb_test "python print t\[0\].symtab" "gdb.python/py-symbol.c.*" "Get symtab" +gdb_test "python print (t\[0\].symtab)" "gdb.python/py-symbol.c.*" "Get symtab" # C++ tests # Recompile binary. @@ -136,14 +136,14 @@ gdb_continue_to_breakpoint "Break in class." gdb_py_test_silent_cmd "python cplusframe = gdb.selected_frame()" "Get Frame" 0 gdb_py_test_silent_cmd "python cplusfunc = cplusframe.block().function" "Get block" 0 -gdb_test "python print cplusfunc.is_variable" "False" "Test func.is_variable" -gdb_test "python print cplusfunc.is_constant" "False" "Test func.is_constant" -gdb_test "python print cplusfunc.is_argument" "False" "Test func.is_argument" -gdb_test "python print cplusfunc.is_function" "True" "Test func.is_function" -gdb_test "python print cplusfunc.name" "SimpleClass::valueofi().*" "Test func.name" -gdb_test "python print cplusfunc.print_name" "SimpleClass::valueofi().*" "Test func.print_name" -gdb_test "python print cplusfunc.linkage_name" "SimpleClass::valueofi().*" "Test func.linkage_name" -gdb_test "python print cplusfunc.addr_class == gdb.SYMBOL_LOC_BLOCK" "True" "Test func.addr_class" +gdb_test "python print (cplusfunc.is_variable)" "False" "Test func.is_variable" +gdb_test "python print (cplusfunc.is_constant)" "False" "Test func.is_constant" +gdb_test "python print (cplusfunc.is_argument)" "False" "Test func.is_argument" +gdb_test "python print (cplusfunc.is_function)" "True" "Test func.is_function" +gdb_test "python print (cplusfunc.name)" "SimpleClass::valueofi().*" "Test func.name" +gdb_test "python print (cplusfunc.print_name)" "SimpleClass::valueofi().*" "Test func.print_name" +gdb_test "python print (cplusfunc.linkage_name)" "SimpleClass::valueofi().*" "Test func.linkage_name" +gdb_test "python print (cplusfunc.addr_class == gdb.SYMBOL_LOC_BLOCK)" "True" "Test func.addr_class" # Test is_valid when the objfile is unloaded. This must be the last # test as it unloads the object file in GDB. @@ -156,8 +156,8 @@ if ![runto_main] then { gdb_breakpoint [gdb_get_line_number "Break at end."] gdb_continue_to_breakpoint "Break at end." gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0 -gdb_test "python print a\[0\].is_valid()" "True" "Test symbol validity" +gdb_test "python print (a\[0\].is_valid())" "True" "Test symbol validity" delete_breakpoints gdb_unload -gdb_test "python print a\[0\].is_valid()" "False" "Test symbol validity" +gdb_test "python print (a\[0\].is_valid())" "False" "Test symbol validity" gdb_test_no_output "python a = None" "Test symbol destructor" diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp index 0d3a5f2d83a..43f8378961b 100644 --- a/gdb/testsuite/gdb.python/py-symtab.exp +++ b/gdb/testsuite/gdb.python/py-symtab.exp @@ -50,29 +50,29 @@ gdb_py_test_silent_cmd "step" "Step to the next line" 0 gdb_py_test_silent_cmd "python new_pc = gdb.selected_frame().find_sal().pc" "Get new PC" 0 # Test sal. -gdb_test "python print sal.symtab" ".*gdb.python/py-symbol.c.*" "Test symtab" -gdb_test "python print sal.pc" "${decimal}" "Test sal.pc" -gdb_test "python print sal.last == (new_pc - 1)" "True" "Test sal.last" -gdb_test "python print sal.line" "$line_no" "Test sal.line" -gdb_test "python print sal.is_valid()" "True" "Test sal.is_valid" +gdb_test "python print (sal.symtab)" ".*gdb.python/py-symbol.c.*" "Test symtab" +gdb_test "python print (sal.pc)" "${decimal}" "Test sal.pc" +gdb_test "python print (sal.last == (new_pc - 1))" "True" "Test sal.last" +gdb_test "python print (sal.line)" "$line_no" "Test sal.line" +gdb_test "python print (sal.is_valid())" "True" "Test sal.is_valid" # Test symbol table. -gdb_test "python print symtab.filename" ".*gdb.python/py-symbol.c.*" "Test symtab.filename" -gdb_test "python print symtab.objfile" "" "Test symtab.objfile" -gdb_test "python print symtab.fullname()" "testsuite/gdb.python/py-symbol.c.*" "Test symtab.fullname" -gdb_test "python print symtab.is_valid()" "True" "Test symtab.is_valid()" -gdb_test "python print \"qq\" in global_symbols" "True" "Test qq in global symbols" -gdb_test "python print \"func\" in global_symbols" "True" "Test func in global symbols" -gdb_test "python print \"main\" in global_symbols" "True" "Test main in global symbols" -gdb_test "python print \"int\" in static_symbols" "True" "Test int in static symbols" -gdb_test "python print \"char\" in static_symbols" "True" "Test char in static symbols" -gdb_test "python print \"simple_struct\" in static_symbols" "True" "Test simple_struct in static symbols" +gdb_test "python print (symtab.filename)" ".*gdb.python/py-symbol.c.*" "Test symtab.filename" +gdb_test "python print (symtab.objfile)" "" "Test symtab.objfile" +gdb_test "python print (symtab.fullname())" "testsuite/gdb.python/py-symbol.c.*" "Test symtab.fullname" +gdb_test "python print (symtab.is_valid())" "True" "Test symtab.is_valid()" +gdb_test "python print (\"qq\" in global_symbols)" "True" "Test qq in global symbols" +gdb_test "python print (\"func\" in global_symbols)" "True" "Test func in global symbols" +gdb_test "python print (\"main\" in global_symbols)" "True" "Test main in global symbols" +gdb_test "python print (\"int\" in static_symbols)" "True" "Test int in static symbols" +gdb_test "python print (\"char\" in static_symbols)" "True" "Test char in static symbols" +gdb_test "python print (\"simple_struct\" in static_symbols)" "True" "Test simple_struct in static symbols" # Test is_valid when the objfile is unloaded. This must be the last # test as it unloads the object file in GDB. gdb_unload -gdb_test "python print sal.is_valid()" "False" "Test sal.is_valid" -gdb_test "python print symtab.is_valid()" "False" "Test symtab.is_valid()" +gdb_test "python print (sal.is_valid())" "False" "Test sal.is_valid" +gdb_test "python print (symtab.is_valid())" "False" "Test symtab.is_valid()" gdb_test_no_output "python sal = None" "Test sal destructor" gdb_test_no_output "python symtab = None" "Test symtab destructor" diff --git a/gdb/testsuite/gdb.python/py-template.exp b/gdb/testsuite/gdb.python/py-template.exp index 5aff73df624..1c855fbda77 100644 --- a/gdb/testsuite/gdb.python/py-template.exp +++ b/gdb/testsuite/gdb.python/py-template.exp @@ -48,12 +48,12 @@ proc test_template_arg {exefile type} { return } # There is no executable code in main(), so we are where we want to be - gdb_test "print foo" ".*" + gdb_test "print (foo)" ".*" gdb_test_no_output "python foo = gdb.history(0)" # Replace '*' with '\*' in regex. regsub -all {\*} $type {\*} t - gdb_test "python print foo.type.template_argument(0)" $t $type + gdb_test "python print (foo.type.template_argument(0))" $t $type } test_template_arg "${binfile}-ci" "const int" diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index 50091352031..e7f2b71a7f0 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -60,7 +60,7 @@ proc test_fields {lang} { global gdb_prompt # .fields() of a typedef should still return the underlying field list - gdb_test "python print len(gdb.parse_and_eval('ts').type.fields())" "2" \ + gdb_test "python print (len(gdb.parse_and_eval('ts').type.fields()))" "2" \ "$lang typedef field list" if {$lang == "c++"} { @@ -68,12 +68,12 @@ proc test_fields {lang} { gdb_py_test_silent_cmd "print c" "print value (c)" 1 gdb_py_test_silent_cmd "python c = gdb.history (0)" "get value (c) from history" 1 gdb_py_test_silent_cmd "python fields = c.type.fields()" "get fields from c.type" 1 - gdb_test "python print len(fields)" "2" "Check number of fields (c)" - 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" + gdb_test "python print (len(fields))" "2" "Check number of fields (c)" + 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" - gdb_test "python print c.type == gdb.parse_and_eval('d').type" "False" - gdb_test "python print c.type == gdb.parse_and_eval('d').type.fields()\[0\].type" \ + gdb_test "python print (c.type == gdb.parse_and_eval('d').type)" "False" + gdb_test "python print (c.type == gdb.parse_and_eval('d').type.fields()\[0\].type)" \ "True" } @@ -81,61 +81,61 @@ proc test_fields {lang} { gdb_py_test_silent_cmd "print st" "print value (st)" 1 gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1 gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields from st.type" 1 - gdb_test "python print len(fields)" "2" "Check number of fields (st)" - 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" + gdb_test "python print (len(fields))" "2" "Check number of fields (st)" + 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" # Regression test for # http://sourceware.org/bugzilla/show_bug.cgi?id=12070. - gdb_test "python print 'type' in dir(fields\[0\])" "True" \ + gdb_test "python print ('type' in dir(fields\[0\]))" "True" \ "Check that dir includes name" # Test Python mapping behavior of gdb.Type for structs/classes - gdb_test "python print len(st.type)" "2" "Check number of fields (st.type)" - gdb_test "python print st.type\['a'\].name" "a" "Check fields lookup by name" - gdb_test "python print \[v.bitpos for v in st.type.itervalues()\]" {\[0L, 32L\]} "Check fields iteration over values" - gdb_test "python print \[(n, v.bitpos) for (n, v) in st.type.items()\]" {\[\('a', 0L\), \('b', 32L\)\]} "Check fields items list" - gdb_test "python print 'a' in st.type" "True" "Check field name exists test" - gdb_test "python print 'nosuch' in st.type" "False" "Check field name nonexists test" - gdb_test "python print not not st.type" "True" "Check conversion to bool" + gdb_test "python print (len(st.type))" "2" "Check number of fields (st.type)" + gdb_test "python print (st.type\['a'\].name)" "a" "Check fields lookup by name" + gdb_test "python print (\[v.bitpos for v in st.type.itervalues()\])" {\[0L?, 32L?\]} "Check fields iteration over values" + gdb_test "python print (\[(n, v.bitpos) for (n, v) in st.type.items()\])" {\[\('a', 0L?\), \('b', 32L?\)\]} "Check fields items list" + gdb_test "python print ('a' in st.type)" "True" "Check field name exists test" + gdb_test "python print ('nosuch' in st.type)" "False" "Check field name nonexists test" + gdb_test "python print (not not st.type)" "True" "Check conversion to bool" # Test rejection of mapping operations on scalar types - gdb_test "python print len (st.type\['a'\].type)" "TypeError: Type is not a structure, union, or enum type.*" - gdb_test "python print st.type\['a'\].type.has_key ('x')" "TypeError: Type is not a structure, union, or enum type.*" - gdb_test "python print st.type\['a'\].type.keys ()" "TypeError: Type is not a structure, union, or enum type.*" - gdb_test "python print st.type\['a'\].type\['x'\]" "TypeError: Type is not a structure, union, or enum type.*" + gdb_test "python print (len (st.type\['a'\].type))" "TypeError: Type is not a structure, union, or enum type.*" + gdb_test "python print (st.type\['a'\].type.has_key ('x'))" "TypeError: Type is not a structure, union, or enum type.*" + gdb_test "python print (st.type\['a'\].type.keys ())" "TypeError: Type is not a structure, union, or enum type.*" + gdb_test "python print (st.type\['a'\].type\['x'\])" "TypeError: Type is not a structure, union, or enum type.*" # Test conversion to bool on scalar types - gdb_test "python print not not st.type\['a'\].type" "True" + gdb_test "python print (not not st.type\['a'\].type)" "True" # Test regression PR python/10805 gdb_py_test_silent_cmd "print ar" "print value (ar)" 1 gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) 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" + gdb_test "python print (len(fields))" "1" "Check the number of fields" + gdb_test "python print (fields\[0\].type)" "" "Check array field type" # Test gdb.Type.array. - gdb_test "python print ar\[0\].cast(ar\[0\].type.array(1))" \ + gdb_test "python print (ar\[0\].cast(ar\[0\].type.array(1)))" \ ".1, 2." "cast to array with one argument" - gdb_test "python print ar\[0\].cast(ar\[0\].type.array(0, 1))" \ + gdb_test "python print (ar\[0\].cast(ar\[0\].type.array(0, 1)))" \ ".1, 2." "cast to array with two arguments" - gdb_test "python print ar\[0\].type == ar\[0\].type" "True" + gdb_test "python print (ar\[0\].type == ar\[0\].type)" "True" # Test gdb.Type.vector. # Note: vectors cast differently than arrays. Here ar[0] is replicated # for the size of the vector. gdb_py_test_silent_cmd \ "python vec1 = ar\[0\].cast(ar\[0\].type.vector(1))" "set vec1" 1 - gdb_test "python print vec1" ".1, 1." "cast to vector with one argument" + gdb_test "python print (vec1)" ".1, 1." "cast to vector with one argument" gdb_py_test_silent_cmd \ "python vec2 = ar\[0\].cast(ar\[0\].type.vector(0, 1))" "set vec2" 1 - gdb_test "python print vec2" ".1, 1." "cast to vector with two arguments" - gdb_test "python print vec1 == vec2" "True" + gdb_test "python print (vec2)" ".1, 1." "cast to vector with two arguments" + gdb_test "python print (vec1 == vec2)" "True" gdb_py_test_silent_cmd \ "python vec3 = ar\[1\].cast(ar\[1\].type.vector(1))" "set vec3" 1 - gdb_test "python print vec1 == vec3" "False" + gdb_test "python print (vec1 == vec3)" "False" } } @@ -144,16 +144,16 @@ proc test_enums {} { gdb_py_test_silent_cmd "print e" "print value (e)" 1 gdb_py_test_silent_cmd "python e = gdb.history (0)" "get value (e) from history" 1 gdb_py_test_silent_cmd "python fields = e.type.fields()" "extract type fields from e" 1 - gdb_test "python print len(fields)" "3" "Check the number of enum fields" - gdb_test "python print fields\[0\].name" "v1" "Check enum field\[0\] name" - gdb_test "python print fields\[1\].name" "v2" "Check enum field\[1\]name" + gdb_test "python print (len(fields))" "3" "Check the number of enum fields" + gdb_test "python print (fields\[0\].name)" "v1" "Check enum field\[0\] name" + gdb_test "python print (fields\[1\].name)" "v2" "Check enum field\[1\]name" # Ditto but by mapping operations - gdb_test "python print len(e.type)" "3" "Check the number of type fields" - gdb_test "python print e.type\['v1'\].name" "v1" "Check enum field lookup by name (v1)" - gdb_test "python print e.type\['v3'\].name" "v3" "Check enum field lookup by name (v2)" - gdb_test "python print \[v.enumval for v in e.type.itervalues()\]" {\[0L, 1L, 2L\]} "Check num fields iteration over values" - gdb_test "python print \[(n, v.enumval) for (n, v) in e.type.items()\]" {\[\('v1', 0L\), \('v2', 1L\), \('v3', 2L\)\]} "Check enum fields items list" + gdb_test "python print (len(e.type))" "3" "Check the number of type fields" + gdb_test "python print (e.type\['v1'\].name)" "v1" "Check enum field lookup by name (v1)" + gdb_test "python print (e.type\['v3'\].name)" "v3" "Check enum field lookup by name (v2)" + gdb_test "python print (\[v.enumval for v in e.type.itervalues()\])" {\[0L?, 1L?, 2L?\]} "Check num fields iteration over values" + gdb_test "python print (\[(n, v.enumval) for (n, v) in e.type.items()\])" {\[\('v1', 0L?\), \('v2', 1L?\), \('v3', 2L?\)\]} "Check enum fields items list" } } proc test_base_class {} { @@ -161,9 +161,9 @@ proc test_base_class {} { gdb_py_test_silent_cmd "print d" "print value (d)" 1 gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value (d) from history" 1 gdb_py_test_silent_cmd "python fields = d.type.fields()" "extract type fields from d" 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 (fields\[0\])" - gdb_test "python print fields\[1\].is_base_class" "False" "Check base class (fields\[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 (fields\[0\])" + gdb_test "python print (fields\[1\].is_base_class)" "False" "Check base class (fields\[1\])" } } @@ -173,9 +173,9 @@ proc test_range {} { # Test a valid range request. gdb_py_test_silent_cmd "print ar" "print value (ar)" 1 gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) 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 range low bound" - gdb_test "python print ar.type.range()\[1\]" "1" "Check range high bound" + gdb_test "python print (len(ar.type.range()))" "2" "Check correct tuple length" + gdb_test "python print (ar.type.range()\[0\])" "0" "Check range low bound" + gdb_test "python print (ar.type.range()\[1\])" "1" "Check range high bound" } with_test_prefix "on ranged type" { @@ -183,15 +183,15 @@ proc test_range {} { gdb_py_test_silent_cmd "print ar" "print value (ar)" 1 gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) 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 low bound" - gdb_test "python print fields\[0\].type.range()\[1\]" "1" "Check range high bound" + gdb_test "python print (fields\[0\].type.range()\[0\])" "0" "Check range low bound" + gdb_test "python print (fields\[0\].type.range()\[1\])" "1" "Check range high bound" } with_test_prefix "on unranged value" { # Test where a range does not exist. gdb_py_test_silent_cmd "print st" "print value (st)" 1 gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1 - gdb_test "python print st.type.range()" "RuntimeError: This type does not have a range.*" "Check range for non ranged type." + gdb_test "python print (st.type.range())" "RuntimeError: This type does not have a range.*" "Check range for non ranged type." } } } @@ -203,8 +203,8 @@ proc test_template {} { "get type of temvar" \ 1 - gdb_test "python print ttype.template_argument(0)" "D" - gdb_test "python print isinstance(ttype.template_argument(0), gdb.Type)" \ + gdb_test "python print (ttype.template_argument(0))" "D" + gdb_test "python print (isinstance(ttype.template_argument(0), gdb.Type))" \ "True" # The next two tests require a GCC that emits DW_TAG_template_*. @@ -215,16 +215,16 @@ proc test_template {} { set have_older_gcc 1 } if $have_older_gcc { setup_xfail *-*-* } - gdb_test "python print ttype.template_argument(1)" "23" + gdb_test "python print (ttype.template_argument(1))" "23" if $have_older_gcc { setup_xfail *-*-* } - gdb_test "python print isinstance(ttype.template_argument(1), gdb.Value)" \ + gdb_test "python print (isinstance(ttype.template_argument(1), gdb.Value))" \ "True" if {[test_compiler_info {gcc-[0-3]-*}] || [test_compiler_info {gcc-4-[0-5]-*}]} { setup_xfail "gcc/46955" *-*-* } - gdb_test "python print ttype.template_argument(2)" "&C::c" + gdb_test "python print (ttype.template_argument(2))" "&C::c" } # Perform C Tests. diff --git a/gdb/testsuite/gdb.python/py-value-cc.exp b/gdb/testsuite/gdb.python/py-value-cc.exp index 9de63b1bd51..5d46889e3a6 100644 --- a/gdb/testsuite/gdb.python/py-value-cc.exp +++ b/gdb/testsuite/gdb.python/py-value-cc.exp @@ -34,13 +34,13 @@ if ![runto_main] { gdb_breakpoint [gdb_get_line_number "Break here."] gdb_continue_to_breakpoint "Break here" ".*Break here.*" -gdb_test "python print str(gdb.parse_and_eval(\"a\").type)" "const A &" -gdb_test "python print str(gdb.parse_and_eval(\"a\").referenced_value().type)" "const A" -gdb_test "python print str(gdb.parse_and_eval(\"int_ref\").type)" "int &" -gdb_test "python print str(gdb.parse_and_eval(\"int_ref\").referenced_value().type)" "int" -gdb_test "python print str(gdb.parse_and_eval(\"int_ref\").referenced_value())" "10" - -gdb_test "python print str(gdb.parse_and_eval(\"int_ptr_ref\").dereference().type)" "int" -gdb_test "python print str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().type)" "int_ptr" -gdb_test "python print str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().dereference())" "10" -gdb_test "python print str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().referenced_value())" "10" +gdb_test "python print (str(gdb.parse_and_eval(\"a\").type))" "const A &" +gdb_test "python print (str(gdb.parse_and_eval(\"a\").referenced_value().type))" "const A" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ref\").type))" "int &" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ref\").referenced_value().type))" "int" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ref\").referenced_value()))" "10" + +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").dereference().type))" "int" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().type))" "int_ptr" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().dereference()))" "10" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().referenced_value()))" "10" diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 3ece58880b7..dffb7d57afe 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -32,20 +32,25 @@ proc build_inferior {exefile lang} { proc test_value_creation {} { global gdb_prompt + global gdb_py_is_py3k 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 + if { $gdb_py_is_py3k == 0 } { + 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" + gdb_test "python print (a)" "\"string test\"" "print 8-bit string" + gdb_test "python print (a.__class__)" "<(type|class) 'gdb.Value'>" "verify type of 8-bit string" + if { $gdb_py_is_py3k == 0 } { + 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__)" "<(type|class) 'gdb.Value'>" "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" + gdb_test "python print ('result = %s' % i.address)" "= None" "Test address attribute in non-addressable value" } proc test_value_numeric_ops {} { @@ -55,42 +60,42 @@ proc test_value_numeric_ops {} { 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" + gdb_test "python print ('result = ' + str(i+j))" " = 7" "add two integer values" + gdb_test "python print ((i+j).__class__)" "<(type|class) 'gdb.Value'>" "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**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" + 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(i-1))" " = 4" "subtract integer value from python integer" + gdb_test "python print ((i-1).__class__)" "<(type|class) 'gdb.Value'>" "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" + 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_no_output "python evalue = gdb.history (0)" - gdb_test "python print int (evalue)" "2" + gdb_test "python print (int (evalue))" "2" # Test pointer arithmethic @@ -100,19 +105,19 @@ proc test_value_numeric_ops {} { gdb_test "print (void *) 5" ".*" "" gdb_test_no_output "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" + 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" { + 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" { + 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"} @@ -125,9 +130,9 @@ proc test_value_boolean {} { "python" "" \ "def test_bool (val):" "" \ " if val:" "" \ - " print 'yay'" "" \ + " print ('yay')" "" \ " else:" "" \ - " print 'nay'" "" \ + " print ('nay')" "" \ "end" "" gdb_test "py test_bool (gdb.Value (True))" "yay" "check evaluation of true boolean value in expression" @@ -144,40 +149,41 @@ proc test_value_boolean {} { } 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" + 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 + global gdb_py_is_py3k gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"] @@ -188,8 +194,10 @@ proc test_value_in_inferior {} { 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" + gdb_test "python print ('result = ' + str(s\['a'\]))" " = 3" "access element inside struct using 8-bit string name" + if { $gdb_py_is_py3k == 0 } { + gdb_test "python print ('result = ' + str(s\[u'a'\]))" " = 3" "access element inside struct using unicode name" + } # Test dereferencing the argv pointer @@ -201,14 +209,14 @@ proc test_value_in_inferior {} { # Check that the dereferenced value is sane if { ! [target_info exists noargs] } { - gdb_test "python print arg0" "0x.*$testfile\"" "verify dereferenced value" + 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" + gdb_test "python print ('result = %s' % 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" + gdb_test "python print ('result = %s' % arg0.address)" "= 0x\[\[:xdigit:\]\]+" "Test address attribute" # Test displaying a variable that is temporarily at a bad address. # But if we can examine what's at memory address 0, then we'll also be @@ -227,7 +235,7 @@ proc test_value_in_inferior {} { if {$can_read_0} { untested $test } else { - gdb_test "python print gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test + gdb_test "python print (gdb.parse_and_eval('*(int*)0'))" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test } # Test Python lazy value handling @@ -236,40 +244,40 @@ proc test_value_in_inferior {} { untested $test } else { gdb_test "python inval = gdb.parse_and_eval('*(int*)0')" - gdb_test "python print inval.is_lazy" "True" + gdb_test "python print (inval.is_lazy)" "True" gdb_test "python inval2 = inval+1" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test gdb_test "python inval.fetch_lazy ()" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test } gdb_test "python argc_lazy = gdb.parse_and_eval('argc')" gdb_test "python argc_notlazy = gdb.parse_and_eval('argc')" gdb_test "python argc_notlazy.fetch_lazy()" - gdb_test "python print argc_lazy.is_lazy" "True" - gdb_test "python print argc_notlazy.is_lazy" "False" + gdb_test "python print (argc_lazy.is_lazy)" "True" + gdb_test "python print (argc_notlazy.is_lazy)" "False" gdb_test "print argc" " = 1" "sanity check argc" - gdb_test "python print argc_lazy.is_lazy" "\r\nTrue" + gdb_test "python print (argc_lazy.is_lazy)" "\r\nTrue" gdb_test_no_output "set argc=2" - gdb_test "python print argc_notlazy" "\r\n1" - gdb_test "python print argc_lazy" "\r\n2" - gdb_test "python print argc_lazy.is_lazy" "False" + gdb_test "python print (argc_notlazy)" "\r\n1" + gdb_test "python print (argc_lazy)" "\r\n2" + gdb_test "python print (argc_lazy.is_lazy)" "False" # 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" + 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" + 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'" + gdb_test "python print (repr(nullst))" "u?'divide\\\\x00et'" } proc test_lazy_strings {} { @@ -280,14 +288,14 @@ proc test_lazy_strings {} { 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" + gdb_test "python print (lstr.type)" "const char \*." "Test type name equality" + gdb_test "python print (sptr.type)" "const char \*." "Test type name equality" gdb_test "print sn" "0x0" gdb_py_test_silent_cmd "python snptr = gdb.history (0)" "Get value from history" 1 gdb_test "python snstr = snptr.lazy_string(length=5)" ".*Cannot create a lazy string with address.*" "Test lazy string" gdb_py_test_silent_cmd "python snstr = snptr.lazy_string(length=0)" "Succesfully create a lazy string" 1 - gdb_test "python print snstr.length" "0" "Test lazy string length" - gdb_test "python print snstr.address" "0" "Test lazy string address" + gdb_test "python print (snstr.length)" "0" "Test lazy string length" + gdb_test "python print (snstr.address)" "0" "Test lazy string address" } @@ -299,14 +307,14 @@ proc test_inferior_function_call {} { gdb_py_test_silent_cmd "python fp1 = gdb.history (0)" "get value from history" 1 gdb_test "python fp1 = fp1.dereference()" "" gdb_test "python result = fp1()" "" - gdb_test "python print result" "void" + gdb_test "python print (result)" "void" # Correct inferior call with arguments. gdb_test "p/x fp2" " = $hex.*" gdb_py_test_silent_cmd "python fp2 = gdb.history (0)" "get value from history" 1 gdb_test "python fp2 = fp2.dereference()" "" gdb_test "python result2 = fp2(10,20)" "" - gdb_test "python print result2" "30" + gdb_test "python print (result2)" "30" # Incorrect to call an int value. gdb_test "p i" " = $decimal.*" @@ -322,10 +330,10 @@ proc test_inferior_function_call {} { # 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\nok=False\nfor file in gdb.objfiles():\n if 'py-value' in file.filename:\n ok=True\nprint (ok)\nend" "True" \ "py-value in file.filename" - gdb_test "python print gdb.objfiles()\[0\].pretty_printers" "\\\[\\\]" + 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." @@ -354,7 +362,7 @@ proc test_value_after_death {} { "delete PTR type" 1 # Now see if the value's type is still valid. - gdb_test "python print castval.type" "PTR ." \ + gdb_test "python print (castval.type)" "PTR ." \ "print value's type" } @@ -379,18 +387,18 @@ proc test_subscript_regression {exefile lang} { "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_test "python print (rptr\[0\])" "2" "Check pointer passed as reference" # Just the most basic test of dynamic_cast -- it is checked in # the C++ tests. - gdb_test "python print bool(gdb.parse_and_eval('base').dynamic_cast(gdb.lookup_type('Derived').pointer()))" \ + gdb_test "python print (bool(gdb.parse_and_eval('base').dynamic_cast(gdb.lookup_type('Derived').pointer())))" \ True # Likewise. - gdb_test "python print gdb.parse_and_eval('base').dynamic_type" \ + gdb_test "python print (gdb.parse_and_eval('base').dynamic_type)" \ "Derived \[*\]" # A static type case. - gdb_test "python print gdb.parse_and_eval('5').dynamic_type" \ + gdb_test "python print (gdb.parse_and_eval('5').dynamic_type)" \ "int" } @@ -403,40 +411,40 @@ proc test_subscript_regression {exefile lang} { "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\]" "gdb.error: Cannot subscript requested type.*" \ + gdb_test "python print (intv)" "1" "Baseline print of a Python value" + gdb_test "python print (intv\[0\])" "gdb.error: 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" + 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" + 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\]" "gdb.error: Cannot subscript requested type.*" \ + gdb_test "python print (pointer\[intv\]\[0\])" "gdb.error: 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" + 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" \ + 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" \ + 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'."\ + gdb_test "python print (type(gdb.parse_and_eval ('5 + 7')))" \ + ".(type|class) 'gdb.Value'."\ "parse_and_eval type test" } @@ -449,10 +457,10 @@ proc test_value_hash {} { "three = gdb.Value(3)" "" \ "vdict = {one:\"one str\",two:\"two str\",three:\"three str\"}" "" \ "end" - gdb_test "python print vdict\[one\]" "one str" "Test dictionary hash" - gdb_test "python print vdict\[two\]" "two str" "Test dictionary hash" - gdb_test "python print vdict\[three\]" "three str" "Test dictionary hash" - gdb_test "python print one.__hash__() == hash(one)" "True" "Test inbuilt hash" + gdb_test "python print (vdict\[one\])" "one str" "Test dictionary hash" + gdb_test "python print (vdict\[two\])" "two str" "Test dictionary hash" + gdb_test "python print (vdict\[three\])" "three str" "Test dictionary hash" + gdb_test "python print (one.__hash__() == hash(one))" "True" "Test inbuilt hash" } # Build C and C++ versions of executable diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index 6f0ce1cc6a7..bf0bf144e67 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -33,7 +33,7 @@ gdb_reinitialize_dir $srcdir/$subdir # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } -gdb_test_multiple "python print 23" "verify python support" { +gdb_test_multiple "python print (23)" "verify python support" { -re "not supported.*$gdb_prompt $" { unsupported "python support is disabled" @@ -49,21 +49,21 @@ gdb_test_multiple "python print 23" "verify python support" { gdb_py_test_multiple "multi-line python command" \ "python" "" \ - "print 23" "" \ + "print (23)" "" \ "end" "23" gdb_py_test_multiple "show python command" \ "define zzq" "Type commands for definition of .* just \"end\"\\.*" \ "python" "" \ - "print 23" "" \ + "print (23)" "" \ "end" "" \ "end" "" \ - "show user zzq" "User command \"zzq\":.* python.*print 23.* 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!'" "" \ + " print ('hello, world!')" "" \ "foo ()" "" \ "end" "hello, world!" @@ -71,15 +71,15 @@ gdb_test "source $srcdir/$subdir/source2.py" "yes" "source source2.py" gdb_test "source -s source2.py" "yes" "source -s source2.py" -gdb_test "python print gdb.current_objfile()" "None" -gdb_test "python print gdb.objfiles()" "\\\[\\\]" +gdb_test "python print (gdb.current_objfile())" "None" +gdb_test "python print (gdb.objfiles())" "\\\[\\\]" # Test http://bugs.python.org/issue4434 workaround in configure.ac -gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/lib-dynload/*.so" +gdb_test "python import itertools; print ('IMPOR'+'TED')" "IMPORTED" "pythonX.Y/lib-dynload/*.so" gdb_test_no_output \ "python x = gdb.execute('printf \"%d\", 23', to_string = True)" -gdb_test "python print x" "23" +gdb_test "python print (x)" "23" # Test post_event. gdb_py_test_multiple "post event insertion" \ @@ -92,7 +92,7 @@ gdb_py_test_multiple "post event insertion" \ "gdb.post_event(Foo())" "" \ "end" "" -gdb_test "python print someVal" "1" "test post event execution" +gdb_test "python print (someVal)" "1" "test post event execution" gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" "Test non callable class" # Test (no) pagination of the executed command. @@ -101,7 +101,7 @@ set lines 10 gdb_test_no_output "set height $lines" set test "verify pagination beforehand" -gdb_test_multiple "python print \"\\n\" * $lines" $test { +gdb_test_multiple "python print (\"\\n\" * $lines)" $test { -re "---Type " { exp_continue } @@ -114,10 +114,10 @@ gdb_test_multiple "python print \"\\n\" * $lines" $test { } gdb_test "q" "Quit.*Error while executing Python.*" "verify pagination beforehand: q" -gdb_test "python if gdb.execute('python print \"\\\\n\" * $lines', to_string=True) == \"\\n\" * [expr $lines + 1]: print \"yes\"" "yes" "gdb.execute does not page" +gdb_test "python if gdb.execute('python print (\"\\\\n\" * $lines)', to_string=True) == \"\\n\" * [expr $lines + 1]: print (\"yes\")" "yes" "gdb.execute does not page" set test "verify pagination afterwards" -gdb_test_multiple "python print \"\\n\" * $lines" $test { +gdb_test_multiple "python print (\"\\n\" * $lines)" $test { -re "---Type " { exp_continue } @@ -134,18 +134,18 @@ gdb_test_no_output "set height 0" gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect help from uiout" -gdb_test "python print a" ".*aliases -- Aliases of other commands.*" "verify help to uiout" +gdb_test "python print (a)" ".*aliases -- Aliases of other commands.*" "verify help to uiout" # Test PR 12212, using InfThread.selected_thread() when no inferior is # loaded. gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1 -gdb_test "python print nothread == None" "True" "Ensure that no threads are returned" +gdb_test "python print (nothread == None)" "True" "Ensure that no threads are returned" gdb_py_test_multiple "register atexit function" \ "python" "" \ "import atexit" "" \ "def printit(arg):" "" \ - " print arg" "" \ + " print (arg)" "" \ "atexit.register(printit, 'good bye world')" "" \ "end" "" @@ -176,33 +176,33 @@ gdb_test "python gdb.decode_line(\"main.c:43\")" \ "gdb.error: No source file named main.c.*" "test decode_line no source named main" gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1 -gdb_test "python print len(symtab)" "2" "Test decode_line current location" -gdb_test "python print symtab\[0\]" "None" "Test decode_line expression parse" -gdb_test "python print len(symtab\[1\])" "1" "Test decode_line current location" -gdb_test "python print symtab\[1\]\[0\].symtab" ".*gdb.python/python.c.*" "Test decode_line current locationn filename" -gdb_test "python print symtab\[1\]\[0\].line" "22" "Test decode_line current location line number" +gdb_test "python print (len(symtab))" "2" "Test decode_line current location" +gdb_test "python print (symtab\[0\])" "None" "Test decode_line expression parse" +gdb_test "python print (len(symtab\[1\]))" "1" "Test decode_line current location" +gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*gdb.python/python.c.*" "Test decode_line current locationn filename" +gdb_test "python print (symtab\[1\]\[0\].line)" "22" "Test decode_line current location line number" gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "test decode_line python.c:26" 1 -gdb_test "python print len(symtab)" "2" "Test decode_line python.c:26 length" -gdb_test "python print symtab\[0\]" "if foo" "Test decode_line expression parse" -gdb_test "python print len(symtab\[1\])" "1" "Test decode_line python.c:26 length" -gdb_test "python print symtab\[1\]\[0\].symtab" ".*gdb.python/python.c.*" "Test decode_line python.c:26 filename" -gdb_test "python print symtab\[1\]\[0\].line" "26" "Test decode_line python.c:26 line number" +gdb_test "python print (len(symtab))" "2" "Test decode_line python.c:26 length" +gdb_test "python print (symtab\[0\])" "if foo" "Test decode_line expression parse" +gdb_test "python print (len(symtab\[1\]))" "1" "Test decode_line python.c:26 length" +gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*gdb.python/python.c.*" "Test decode_line python.c:26 filename" +gdb_test "python print (symtab\[1\]\[0\].line)" "26" "Test decode_line python.c:26 line number" gdb_test "python gdb.decode_line(\"randomfunc\")" \ "gdb.error: Function \"randomfunc\" not defined.*" "test decode_line randomfunc" gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1 -gdb_test "python print len(symtab)" "2" "Test decode_line func1 length" -gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length" -gdb_test "python print symtab\[1\]\[0\].symtab" ".*gdb.python/python-1.c.*" "Test decode_line func1 filename" -gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number" +gdb_test "python print (len(symtab))" "2" "Test decode_line func1 length" +gdb_test "python print (len(symtab\[1\]))" "1" "Test decode_line func1 length" +gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*gdb.python/python-1.c.*" "Test decode_line func1 filename" +gdb_test "python print (symtab\[1\]\[0\].line)" "19" "Test decode_line func1 line number" gdb_py_test_silent_cmd {python symtab = gdb.decode_line ("func1,func2")} \ "test decode_line func1,func2" 1 -gdb_test {python print symtab[0]} ",func2" "stop at comma in linespec" +gdb_test {python print (symtab[0])} ",func2" "stop at comma in linespec" # gdb.write -gdb_test "python print sys.stderr" ".*gdb.GdbOutputErrorFile instance at.*" "Test stderr location" -gdb_test "python print sys.stdout" ".*gdb.GdbOutputFile instance at.*" "Test stdout location" +gdb_test "python print (sys.stderr)" ".*gdb.GdbOutputErrorFile (instance|object) at.*" "Test stderr location" +gdb_test "python print (sys.stdout)" ".*gdb.GdbOutputFile (instance|object) at.*" "Test stdout location" gdb_test "python gdb.write(\"Foo\\n\")" "Foo" "Test default write" gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error stream" "Test stderr write" gdb_test "python gdb.write(\"Normal stream\\n\", stream=gdb.STDOUT)" "Normal stream" "Test stdout write" @@ -362,7 +362,7 @@ gdb_py_test_multiple "prompt substitution readline" \ "end" "" gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" { - -re "Python Exception Python exception called.*" { + -re "Python Exception <(type 'exceptions.|class ')RuntimeError'> Python exception called.*" { pass "set hook" } } @@ -395,9 +395,9 @@ if ![runto_main] then { runto [gdb_get_line_number "Break at func2 call site."] gdb_py_test_silent_cmd "python line = gdb.selected_frame().find_sal().line" "Get line number of func2 call site" 1 -gdb_test "python print gdb.find_pc_line(gdb.selected_frame().pc()).line == line" "True" "Test find_pc_line at func2 call site" +gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line == line)" "True" "Test find_pc_line at func2 call site" gdb_py_test_silent_cmd "step" "Step into func2" 1 gdb_py_test_silent_cmd "up" "Step out of func2" 1 -gdb_test "python print gdb.find_pc_line(gdb.selected_frame().pc()).line > line" "True" "Test find_pc_line with resume address" +gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line > line)" "True" "Test find_pc_line with resume address" diff --git a/gdb/testsuite/gdb.python/source2.py b/gdb/testsuite/gdb.python/source2.py index 1c38206bd85..d53bb785105 100644 --- a/gdb/testsuite/gdb.python/source2.py +++ b/gdb/testsuite/gdb.python/source2.py @@ -15,4 +15,4 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -print 'y%ss' % 'e' +print ('y%ss' % 'e') diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 781ccc858c0..38a8ac674ef 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1550,7 +1550,10 @@ proc skip_java_tests {} { proc skip_python_tests {} { global gdb_prompt - gdb_test_multiple "python print 'test'" "verify python support" { + global gdb_py_is_py3k + global gdb_py_is_py24 + + gdb_test_multiple "python print ('test')" "verify python support" { -re "not supported.*$gdb_prompt $" { unsupported "Python support is disabled." return 1 @@ -1558,6 +1561,26 @@ proc skip_python_tests {} { -re "$gdb_prompt $" {} } + set gdb_py_is_py24 0 + gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" { + -re "3.*$gdb_prompt $" { + set gdb_py_is_py3k 1 + } + -re ".*$gdb_prompt $" { + set gdb_py_is_py3k 0 + } + } + if { $gdb_py_is_py3k == 0 } { + gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" { + -re "\[45\].*$gdb_prompt $" { + set gdb_py_is_py24 1 + } + -re ".*$gdb_prompt $" { + set gdb_py_is_py24 0 + } + } + } + return 0 } -- 2.30.2