Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright (C) 2011-2014 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 { | |
31 | fail "Can't run to main" | |
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 | |
6dddd6a5 DE |
45 | gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \ |
46 | "${testfile}" | |
47 | gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \ | |
48 | "Objfile not found\\.\r\n${python_error_text}" | |
49 | ||
7c50a931 DE |
50 | set binfile_build_id [get_build_id $binfile] |
51 | if [string compare $binfile_build_id ""] { | |
52 | verbose -log "binfile_build_id = $binfile_build_id" | |
53 | gdb_test "python print (objfile.build_id)" "$binfile_build_id" \ | |
54 | "Get objfile build id" | |
6dddd6a5 DE |
55 | gdb_test "python print (gdb.lookup_objfile (\"$binfile_build_id\", by_build_id=True).filename)" \ |
56 | "${testfile}" | |
7c50a931 DE |
57 | } else { |
58 | unsupported "build-id is not supported by the compiler" | |
59 | } | |
60 | ||
6dddd6a5 DE |
61 | # Other lookup_objfile_by_build_id tests we can do, even if compiler doesn't |
62 | # support them. | |
63 | gdb_test "python print (gdb.lookup_objfile (\"foo\", by_build_id=True))" \ | |
64 | "Not a valid build id\\.\r\n${python_error_text}" | |
65 | gdb_test "python print (gdb.lookup_objfile (\"1234abcdef\", by_build_id=True))" \ | |
66 | "Objfile not found\\.\r\n${python_error_text}" | |
67 | ||
d096d8c1 DE |
68 | gdb_test "python print (objfile.progspace)" "<gdb\.Progspace object at .*>" \ |
69 | "Get objfile program space" | |
9325cb04 | 70 | gdb_test "python print (objfile.is_valid())" "True" \ |
29703da4 PM |
71 | "Get objfile validity" |
72 | gdb_unload | |
9325cb04 | 73 | gdb_test "python print (objfile.is_valid())" "False" \ |
29703da4 | 74 | "Get objfile validity after unload" |
02be9a71 DE |
75 | |
76 | gdb_py_test_silent_cmd "python objfile.random_attribute = 42" \ | |
77 | "Set random attribute in objfile" 1 | |
78 | gdb_test "python print (objfile.random_attribute)" "42" \ | |
79 | "Verify set of random attribute in objfile" | |
86e4ed39 DE |
80 | |
81 | # Now build another copy of the testcase, this time without debug info. | |
82 | ||
83 | if { [prepare_for_testing ${testfile}.exp ${testfile}2 ${srcfile} {nodebug ldflags=-Wl,--strip-debug}] } { | |
84 | return -1 | |
85 | } | |
86 | ||
87 | if ![runto_main] { | |
88 | fail "Can't run to main" | |
89 | return 0 | |
90 | } | |
91 | ||
92 | gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \ | |
93 | "Get no-debug objfile file" 1 | |
94 | ||
a0be3e44 DE |
95 | gdb_test "python print (objfile.owner)" "None" \ |
96 | "Test owner of real objfile." | |
97 | ||
86e4ed39 DE |
98 | gdb_test "p main" "= {<text variable, no debug info>} $hex <main>" \ |
99 | "print main without debug info" | |
100 | ||
101 | gdb_py_test_silent_cmd "python objfile.add_separate_debug_file(\"${binfile}\")" \ | |
102 | "Add separate debug file file" 1 | |
103 | ||
104 | gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \ | |
105 | "Get separate debug info objfile" 1 | |
106 | ||
a0be3e44 DE |
107 | gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \ |
108 | "Test owner of separate debug file" | |
109 | ||
86e4ed39 DE |
110 | gdb_test "p main" "= {int \\(\\)} $hex <main>" \ |
111 | "print main with debug info" | |
6dddd6a5 DE |
112 | |
113 | # Separate debug files are not findable. | |
114 | if { [get_python_valueof "sep_objfile.build_id" "None"] != "None" } { | |
115 | gdb_test "python print (gdb.lookup_objfile (sep_objfile.build_id, by_build_id=True))" \ | |
116 | "Objfile not found\\.\r\n${python_error_text}" | |
117 | } |