54c256eb2e0d9e6530fc727fe62d38e2cad420bd
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / python-helper.exp
1 # Copyright 2021 Free Software Foundation, Inc.
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 test exercises the gdb-gdb.py helper script that is generated
17 # into the GDB build directory. This script is intended for use by
18 # developers to make debugging GDB easier.
19
20 load_lib selftest-support.exp
21
22 if [target_info exists gdb,noinferiorio] {
23 verbose "Skipping because of no inferiorio capabilities."
24 return
25 }
26
27 # Find the helper script in the GDB build directory.
28 set py_helper_script [file dirname $GDB]/gdb-gdb.py
29 if { ![file readable $py_helper_script] \
30 || [file type $py_helper_script] != "file" } {
31 untested "failed to find gdb-gdb.py helper script"
32 return
33 }
34
35 # Start GDB and check that we have python support.
36 gdb_start
37 if { [skip_python_tests] } {
38 untested "skipped gdb-gdb.py tests due to lack of python support"
39 return
40 }
41 gdb_exit
42
43 # The main test. This is called by the self-test framework once GDB
44 # has been started on a copy of itself.
45 proc test_python_helper {} {
46 global py_helper_script decimal hex gdb_prompt
47 global inferior_spawn_id
48
49 # Source the python helper script. This script registers the
50 # pretty printer for the object file called 'gdb', however, in our
51 # selftests we rename 'gdb' to 'xgdb', so the pretty printer
52 # doesn't get registered by default.
53 #
54 # So, after sourcing the script we do our own objfile scan and
55 # register the pretty printer for the objfile called 'xgdb'.
56 gdb_test_no_output "source $py_helper_script" \
57 "source gdb-gdb.py helper script"
58 gdb_test [multi_line_input \
59 "python" \
60 "for objfile in gdb.objfiles():" \
61 " if os.path.basename(objfile.filename) == \"xgdb\":" \
62 " objfile.pretty_printers.append(type_lookup_function)" \
63 "end"] ".*" \
64 "register the type pretty printer"
65
66 # Now place a breakpoint somewhere useful. This can be any function that:
67 # (a) is easy to reach by issuing a simple gdb command, and
68 # (b) is unlikely to be modified very often within gdb, and
69 # (c) has a parameter that is either a 'struct type *' or a 'struct value *'.
70 gdb_breakpoint value_print
71
72 # Adjust the prompt on the outer gdb, this just makes things a
73 # little clearer when trying to unpick which GDB is active.
74 gdb_test_multiple "set prompt (xgdb) " "set xgdb prompt" {
75 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
76 pass $gdb_test_name
77 }
78 }
79
80 # Send a command to the outer GDB to continue the inner GDB. The
81 # stop is being detected from the inner GDB, hence the use of -i
82 # here.
83 gdb_test_multiple "continue" "start inner gdb" {
84 -i "$inferior_spawn_id"
85 -re "\r\n$gdb_prompt $" {
86 pass $gdb_test_name
87 }
88 }
89
90 # Send a command to the inner GDB (hence send_inferior), this
91 # should result in the outer GDB stopping at the breakpoint we
92 # just created.
93 send_inferior "print 1\n"
94 gdb_test_multiple "" "hit breakpoint in inner gdb" {
95 -re "hit Breakpoint $decimal, value_print.*\\(xgdb\\) $" {
96 pass $gdb_test_name
97 }
98 }
99
100 # Now inspect the type of parameter VAL, this should trigger the
101 # pretty printers.
102 set answer [multi_line \
103 "${decimal} = " \
104 "{pointer_type = 0x0," \
105 " reference_type = 0x0," \
106 " chain = 0x0," \
107 " instance_flags = 0," \
108 " length = $decimal," \
109 " main_type = $hex}" \
110 "\\(xgdb\\) $"]
111 gdb_test_multiple "print *val->type" "pretty print type" {
112 -re "$answer" {
113 pass $gdb_test_name
114 }
115 -re "There is no member named.*\r\n\\(xgdb\\) $" {
116 fail $gdb_test_name
117 }
118 }
119
120 set answer [multi_line \
121 "$decimal = " \
122 "{name = $hex \"int\"," \
123 " code = TYPE_CODE_INT," \
124 " flags = \[^\r\n\]+," \
125 " owner = $hex \\(gdbarch\\)," \
126 " target_type = 0x0," \
127 " type_specific_field = TYPE_SPECIFIC_NONE}" \
128 "\\(xgdb\\) $"]
129 gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type" {
130 -re "$answer" {
131 pass $gdb_test_name
132 }
133 -re "There is no member named.*\r\n\\(xgdb\\) $" {
134 fail $gdb_test_name
135 }
136 }
137
138 return 0
139 }
140
141 # Use the self-test framework to run the test.
142 do_self_tests captured_main test_python_helper
This page took 0.034344 seconds and 3 git commands to generate.