]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2012-2024 Free Software Foundation, Inc. |
7b282c5a SCR |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This file is part of the GDB testsuite. It tests the mechanism | |
17 | # exposing values to Python. | |
18 | ||
d82e5429 | 19 | require allow_cplus_tests allow_python_tests |
7b282c5a | 20 | |
ac52f9a2 | 21 | standard_testfile .cc |
7b282c5a | 22 | |
5b362f04 | 23 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { |
7b282c5a SCR |
24 | return -1 |
25 | } | |
26 | ||
7b282c5a SCR |
27 | if ![runto_main] { |
28 | return -1 | |
29 | } | |
30 | ||
31 | gdb_breakpoint [gdb_get_line_number "Break here."] | |
32 | gdb_continue_to_breakpoint "Break here" ".*Break here.*" | |
33 | ||
9325cb04 PK |
34 | gdb_test "python print (str(gdb.parse_and_eval(\"a\").type))" "const A &" |
35 | gdb_test "python print (str(gdb.parse_and_eval(\"a\").referenced_value().type))" "const A" | |
36 | gdb_test "python print (str(gdb.parse_and_eval(\"int_ref\").type))" "int &" | |
37 | gdb_test "python print (str(gdb.parse_and_eval(\"int_ref\").referenced_value().type))" "int" | |
38 | gdb_test "python print (str(gdb.parse_and_eval(\"int_ref\").referenced_value()))" "10" | |
39 | ||
40 | gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").dereference().type))" "int" | |
41 | gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().type))" "int_ptr" | |
42 | gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().dereference()))" "10" | |
43 | gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().referenced_value()))" "10" | |
a16b0e22 SC |
44 | |
45 | # Tests for gdb.Value[gdb.Field] | |
46 | gdb_test_no_output "python b = gdb.parse_and_eval('b')" "init b" | |
47 | gdb_test_no_output "python b_fields = b.type.fields()" "init b_fields" | |
48 | gdb_test_no_output "python b_obj = gdb.parse_and_eval('b_obj')" "init b_obj" | |
49 | gdb_test_no_output "python b_ref = gdb.parse_and_eval('b_ref')" "init b_ref" | |
50 | gdb_test_no_output "python b_td = gdb.parse_and_eval('b_td')" "init b_td" | |
51 | gdb_test_no_output "python u = gdb.parse_and_eval('u')" "init u" | |
52 | gdb_test_no_output "python u_fields = u.type.fields()" "init u_fields" | |
b5b08fb4 SC |
53 | gdb_test_no_output "python x = gdb.parse_and_eval('x')" "init x" |
54 | gdb_test_no_output "python x_fields = x.type.fields()" "init x_fields" | |
55 | gdb_test_no_output "python uu = gdb.parse_and_eval('uu')" "init uu" | |
56 | gdb_test_no_output "python uu_fields = uu.type.fields()" "init uu_fields" | |
57 | gdb_test_no_output "python x_ptr = gdb.parse_and_eval('x_ptr')" "init x_ptr" | |
58 | gdb_test_no_output "python xtd = gdb.parse_and_eval('xtd')" "init xtd" | |
59 | ||
60 | gdb_test "python print(b\[b_fields\[1\]\])" "97 'a'" "b.a via field" | |
a16b0e22 SC |
61 | gdb_test "python print(b\[b_fields\[0\]\].type)" "A" \ |
62 | "type of b's base class via field" | |
63 | gdb_test "python print(b\[b_fields\[0\]\]\['a'\])" "10" "b.A::a via field" | |
64 | ||
65 | gdb_test "python print(b_obj\[b_fields\[1\]\])" "98 'b'" "b_obj->a via field" | |
66 | gdb_test "python print(b_obj\[b_fields\[0\]\].type.target())" "A" \ | |
67 | "type of b_obj's base class via field" | |
68 | gdb_test "python print(b_obj\[b_fields\[0\]\]\['a'\])" "100" \ | |
69 | "b_obj->A::a via field" | |
70 | ||
71 | gdb_test "python print(b_ref\[b_fields\[1\]\])" "98 'b'" "b_ref.a via field" | |
72 | gdb_test "python print(b_ref\[b_fields\[0\]\].type.target())" "A" \ | |
73 | "type of b_ref's base class via field" | |
74 | gdb_test "python print(b_ref\[b_fields\[0\]\]\['a'\])" "100" \ | |
75 | "b_ref.A::a via field" | |
76 | ||
77 | gdb_test "python print(b_td\[b_fields\[1\]\])" "98 'b'" "b_td.a via field" | |
78 | gdb_test "python print(b_td\[b_fields\[0\]\].type.target())" "A" \ | |
79 | "type of b_td's base class via field" | |
80 | gdb_test "python print(b_td\[b_fields\[0\]\]\['a'\])" "100" \ | |
81 | "b_td.A::a via field" | |
82 | ||
a0d5ef86 TV |
83 | gdb_test "python print(hex(u\[u_fields\[0\]\]))" "0x63636363.*" \ |
84 | "u's first field via field" | |
a16b0e22 | 85 | gdb_test "python print(u\[u_fields\[1\]\])" "99.*" "u's second field via field" |
b5b08fb4 | 86 | |
d7fc3181 SM |
87 | gdb_test "python print(len(x_fields))" "2" "number for fields in u" |
88 | gdb_test "python print(x\[x_fields\[0\]\]\['x'\])" "101" "x.x via field" | |
89 | gdb_test "python print(x\[x_fields\[1\]\]\['a'\])" "102" "x.a via field" | |
90 | gdb_test "python print(x_ptr\[x_fields\[0\]\]\['x'\])" "101" "x_ptr->x via field" | |
91 | gdb_test "python print(x_ptr\[x_fields\[1\]\]\['a'\])" "102" "x_ptr->a via field" | |
92 | gdb_test "python print(xtd\[x_fields\[0\]\]\['x'\])" "101" "xtd->x via field" | |
93 | gdb_test "python print(xtd\[x_fields\[1\]\]\['a'\])" "102" "xtd->a via field" | |
94 | ||
95 | gdb_test "python print(len(uu_fields))" "2" "number of fields in uu" | |
96 | gdb_test "python print(uu\[uu_fields\[0\]\]\['x'\])" "1000" "uu.x via field" | |
97 | gdb_test "python print(uu\[uu_fields\[1\]\]\['a'\])" "1000" "uu.a via field" | |
f7bd0f78 SC |
98 | |
99 | # Test overloaded operators. | |
100 | gdb_test_no_output "python a = gdb.parse_and_eval('a')" "init a" | |
d7fc3181 | 101 | gdb_test "python print(a + 5)" "10" "a + 5" |