1 # Copyright 2021 Free Software Foundation, Inc.
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.
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.
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/>.
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.
20 load_lib selftest-support.exp
22 if [target_info exists gdb,noinferiorio] {
23 verbose "Skipping because of no inferiorio capabilities."
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"
35 # Start GDB and check that we have python support.
37 if { [skip_python_tests] } {
38 untested "skipped gdb-gdb.py tests due to lack of python support"
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
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.
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 \
60 "for objfile in gdb.objfiles():" \
61 " if os.path.basename(objfile.filename) == \"xgdb\":" \
62 " objfile.pretty_printers.append(type_lookup_function)" \
64 "register the type pretty printer"
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
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\[)\] $" {
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
83 gdb_test_multiple "continue" "start inner gdb" {
84 -i "$inferior_spawn_id"
85 -re "\r\n$gdb_prompt $" {
90 # Send a command to the inner GDB (hence send_inferior), this
91 # should result in the outer GDB stopping at the breakpoint we
93 send_inferior "print 1\n"
94 gdb_test_multiple "" "hit breakpoint in inner gdb" {
95 -re "hit Breakpoint $decimal, value_print.*\\(xgdb\\) $" {
100 # Now inspect the type of parameter VAL, this should trigger the
102 set answer [multi_line \
104 "{pointer_type = 0x0," \
105 " reference_type = 0x0," \
107 " instance_flags = 0," \
108 " length = $decimal," \
109 " main_type = $hex}" \
111 gdb_test_multiple "print *val->type" "pretty print type" {
115 -re "There is no member named.*\r\n\\(xgdb\\) $" {
120 set answer [multi_line \
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}" \
129 gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type" {
133 -re "There is no member named.*\r\n\\(xgdb\\) $" {
141 # Use the self-test framework to run the test.
142 do_self_tests captured_main test_python_helper