1 # Copyright (C) 2011-2015 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 file is part of the GDB testsuite. It tests the program space
19 load_lib gdb-python.exp
23 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
27 # Skip all tests if Python scripting is not enabled.
28 if { [skip_python_tests] } { continue }
30 if ![runto_main] then {
31 fail "Can't run to main"
35 set python_error_text "Error while executing Python code\\."
37 gdb_py_test_silent_cmd "python sym = gdb.lookup_symbol(\"some_var\")" \
38 "Find a symbol in objfile" 1
39 gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
40 "Get backing object file" 1
42 gdb_test "python print (objfile.filename)" "${testfile}" \
43 "Get objfile file name"
45 gdb_test "python print (objfile.username)" "${testfile}" \
46 "Get objfile user name"
48 gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \
50 gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \
51 "Objfile not found\\.\r\n${python_error_text}"
53 set binfile_build_id [get_build_id $binfile]
54 if [string compare $binfile_build_id ""] {
55 verbose -log "binfile_build_id = $binfile_build_id"
56 gdb_test "python print (objfile.build_id)" "$binfile_build_id" \
57 "Get objfile build id"
58 gdb_test "python print (gdb.lookup_objfile (\"$binfile_build_id\", by_build_id=True).filename)" \
61 unsupported "build-id is not supported by the compiler"
64 # Other lookup_objfile_by_build_id tests we can do, even if compiler doesn't
66 gdb_test "python print (gdb.lookup_objfile (\"foo\", by_build_id=True))" \
67 "Not a valid build id\\.\r\n${python_error_text}"
68 gdb_test "python print (gdb.lookup_objfile (\"1234abcdef\", by_build_id=True))" \
69 "Objfile not found\\.\r\n${python_error_text}"
71 gdb_test "python print (objfile.progspace)" "<gdb\.Progspace object at .*>" \
72 "Get objfile program space"
73 gdb_test "python print (objfile.is_valid())" "True" \
74 "Get objfile validity"
76 gdb_test "python print (objfile.is_valid())" "False" \
77 "Get objfile validity after unload"
79 gdb_py_test_silent_cmd "python objfile.random_attribute = 42" \
80 "Set random attribute in objfile" 1
81 gdb_test "python print (objfile.random_attribute)" "42" \
82 "Verify set of random attribute in objfile"
84 # Verify invalid objfile handling.
86 if { [gdb_unload] < 0 } {
87 fail "unload all files"
91 gdb_test "python print objfile.filename" "None" \
92 "objfile.filename after objfile is unloaded"
93 gdb_test "python print objfile.username" "None" \
94 "objfile.username after objfile is unloaded"
96 # Now build another copy of the testcase, this time without debug info.
98 if { [prepare_for_testing ${testfile}.exp ${testfile}2 ${srcfile} {nodebug ldflags=-Wl,--strip-debug}] } {
103 fail "Can't run to main"
107 gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \
108 "Get no-debug objfile file" 1
110 gdb_test "python print (objfile.owner)" "None" \
111 "Test owner of real objfile."
113 gdb_test "p main" "= {<text variable, no debug info>} $hex <main>" \
114 "print main without debug info"
116 gdb_py_test_silent_cmd "python objfile.add_separate_debug_file(\"${binfile}\")" \
117 "Add separate debug file file" 1
119 gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \
120 "Get separate debug info objfile" 1
122 gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \
123 "Test owner of separate debug file"
125 gdb_test "python print (sep_objfile.owner.username)" "${testfile}2" \
126 "Test user-name of owner of separate debug file"
128 gdb_test "p main" "= {int \\(\\)} $hex <main>" \
129 "print main with debug info"
131 # Separate debug files are not findable.
132 if { [get_python_valueof "sep_objfile.build_id" "None"] != "None" } {
133 gdb_test "python print (gdb.lookup_objfile (sep_objfile.build_id, by_build_id=True))" \
134 "Objfile not found\\.\r\n${python_error_text}"
137 # An objfile that was a symlink to a differently named file is still
138 # findable with its original name.
139 set symlink_binary [standard_output_file "symlink-binary"]
140 remote_exec host "rm -f ${symlink_binary}"
141 remote_exec host "ln -sf ${testfile} ${symlink_binary}"
142 if [remote_file host exists "${symlink_binary}"] {
143 clean_restart "${symlink_binary}"
144 gdb_test "python print (gdb.lookup_objfile (\"${symlink_binary}\").filename)" \
145 "${testfile}" "gdb.lookup_objfile of symlinked binary"