Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2011-2016 Free Software Foundation, Inc. |
29703da4 PM |
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 program space | |
17 | # support in Python. | |
18 | ||
29703da4 PM |
19 | load_lib gdb-python.exp |
20 | ||
b4a58790 | 21 | standard_testfile |
29703da4 PM |
22 | |
23 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { | |
24 | return -1 | |
25 | } | |
26 | ||
27 | # Skip all tests if Python scripting is not enabled. | |
28 | if { [skip_python_tests] } { continue } | |
29 | ||
30 | if ![runto_main] then { | |
bc6c7af4 | 31 | fail "can't run to main" |
29703da4 PM |
32 | return 0 |
33 | } | |
34 | ||
6dddd6a5 DE |
35 | set python_error_text "Error while executing Python code\\." |
36 | ||
29703da4 PM |
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 | |
41 | ||
6dddd6a5 | 42 | gdb_test "python print (objfile.filename)" "${testfile}" \ |
14ea52ee | 43 | "Get objfile file name" |
7c50a931 | 44 | |
3a8b707a DE |
45 | gdb_test "python print (objfile.username)" "${testfile}" \ |
46 | "Get objfile user name" | |
47 | ||
0f6ed0e0 TT |
48 | gdb_test_no_output "python dir(objfile)" |
49 | ||
6dddd6a5 | 50 | gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \ |
d60a9221 | 51 | "${testfile}" "print lookup_objfile filename" |
6dddd6a5 DE |
52 | gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \ |
53 | "Objfile not found\\.\r\n${python_error_text}" | |
54 | ||
7c50a931 DE |
55 | set binfile_build_id [get_build_id $binfile] |
56 | if [string compare $binfile_build_id ""] { | |
57 | verbose -log "binfile_build_id = $binfile_build_id" | |
58 | gdb_test "python print (objfile.build_id)" "$binfile_build_id" \ | |
59 | "Get objfile build id" | |
6dddd6a5 | 60 | gdb_test "python print (gdb.lookup_objfile (\"$binfile_build_id\", by_build_id=True).filename)" \ |
d60a9221 | 61 | "${testfile}" "print lookup_objfile filename by build-id" |
7c50a931 DE |
62 | } else { |
63 | unsupported "build-id is not supported by the compiler" | |
64 | } | |
65 | ||
6dddd6a5 DE |
66 | # Other lookup_objfile_by_build_id tests we can do, even if compiler doesn't |
67 | # support them. | |
68 | gdb_test "python print (gdb.lookup_objfile (\"foo\", by_build_id=True))" \ | |
d60a9221 SDJ |
69 | "Not a valid build id\\.\r\n${python_error_text}" \ |
70 | "print invalid file lookup_objfile by build-id" | |
6dddd6a5 | 71 | gdb_test "python print (gdb.lookup_objfile (\"1234abcdef\", by_build_id=True))" \ |
d60a9221 SDJ |
72 | "Objfile not found\\.\r\n${python_error_text}" \ |
73 | "print invalid file lookup_objfile by build-id 2" | |
6dddd6a5 | 74 | |
d096d8c1 DE |
75 | gdb_test "python print (objfile.progspace)" "<gdb\.Progspace object at .*>" \ |
76 | "Get objfile program space" | |
9325cb04 | 77 | gdb_test "python print (objfile.is_valid())" "True" \ |
29703da4 PM |
78 | "Get objfile validity" |
79 | gdb_unload | |
9325cb04 | 80 | gdb_test "python print (objfile.is_valid())" "False" \ |
29703da4 | 81 | "Get objfile validity after unload" |
02be9a71 DE |
82 | |
83 | gdb_py_test_silent_cmd "python objfile.random_attribute = 42" \ | |
84 | "Set random attribute in objfile" 1 | |
85 | gdb_test "python print (objfile.random_attribute)" "42" \ | |
86 | "Verify set of random attribute in objfile" | |
86e4ed39 | 87 | |
3a8b707a DE |
88 | # Verify invalid objfile handling. |
89 | ||
90 | if { [gdb_unload] < 0 } { | |
91 | fail "unload all files" | |
92 | return -1 | |
93 | } | |
94 | ||
40d2f8d6 | 95 | gdb_test "python print(objfile.filename)" "None" \ |
3a8b707a | 96 | "objfile.filename after objfile is unloaded" |
40d2f8d6 | 97 | gdb_test "python print(objfile.username)" "None" \ |
3a8b707a DE |
98 | "objfile.username after objfile is unloaded" |
99 | ||
86e4ed39 DE |
100 | # Now build another copy of the testcase, this time without debug info. |
101 | ||
102 | if { [prepare_for_testing ${testfile}.exp ${testfile}2 ${srcfile} {nodebug ldflags=-Wl,--strip-debug}] } { | |
103 | return -1 | |
104 | } | |
105 | ||
106 | if ![runto_main] { | |
bc6c7af4 | 107 | fail "can't run to main" |
86e4ed39 DE |
108 | return 0 |
109 | } | |
110 | ||
dac804df | 111 | gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \ |
86e4ed39 DE |
112 | "Get no-debug objfile file" 1 |
113 | ||
a0be3e44 DE |
114 | gdb_test "python print (objfile.owner)" "None" \ |
115 | "Test owner of real objfile." | |
116 | ||
86e4ed39 DE |
117 | gdb_test "p main" "= {<text variable, no debug info>} $hex <main>" \ |
118 | "print main without debug info" | |
119 | ||
120 | gdb_py_test_silent_cmd "python objfile.add_separate_debug_file(\"${binfile}\")" \ | |
121 | "Add separate debug file file" 1 | |
122 | ||
123 | gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \ | |
124 | "Get separate debug info objfile" 1 | |
125 | ||
a0be3e44 DE |
126 | gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \ |
127 | "Test owner of separate debug file" | |
128 | ||
3a8b707a DE |
129 | gdb_test "python print (sep_objfile.owner.username)" "${testfile}2" \ |
130 | "Test user-name of owner of separate debug file" | |
131 | ||
86e4ed39 DE |
132 | gdb_test "p main" "= {int \\(\\)} $hex <main>" \ |
133 | "print main with debug info" | |
6dddd6a5 DE |
134 | |
135 | # Separate debug files are not findable. | |
136 | if { [get_python_valueof "sep_objfile.build_id" "None"] != "None" } { | |
137 | gdb_test "python print (gdb.lookup_objfile (sep_objfile.build_id, by_build_id=True))" \ | |
d60a9221 SDJ |
138 | "Objfile not found\\.\r\n${python_error_text}" \ |
139 | "print lookup_objfile of separate debug file" | |
6dddd6a5 | 140 | } |
e02c96a7 DE |
141 | |
142 | # An objfile that was a symlink to a differently named file is still | |
143 | # findable with its original name. | |
144 | set symlink_binary [standard_output_file "symlink-binary"] | |
145 | remote_exec host "rm -f ${symlink_binary}" | |
146 | remote_exec host "ln -sf ${testfile} ${symlink_binary}" | |
147 | if [remote_file host exists "${symlink_binary}"] { | |
148 | clean_restart "${symlink_binary}" | |
149 | gdb_test "python print (gdb.lookup_objfile (\"${symlink_binary}\").filename)" \ | |
150 | "${testfile}" "gdb.lookup_objfile of symlinked binary" | |
151 | } |