New "owner" attribute for gdb.Objfile.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-objfile.exp
1 # Copyright (C) 2011-2014 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 file is part of the GDB testsuite. It tests the program space
17 # support in Python.
18
19 load_lib gdb-python.exp
20
21 standard_testfile
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
35 gdb_py_test_silent_cmd "python sym = gdb.lookup_symbol(\"some_var\")" \
36 "Find a symbol in objfile" 1
37 gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
38 "Get backing object file" 1
39
40 gdb_test "python print (objfile.filename)" ".*py-objfile.*" \
41 "Get objfile file name"
42
43 set binfile_build_id [get_build_id $binfile]
44 if [string compare $binfile_build_id ""] {
45 verbose -log "binfile_build_id = $binfile_build_id"
46 gdb_test "python print (objfile.build_id)" "$binfile_build_id" \
47 "Get objfile build id"
48 } else {
49 unsupported "build-id is not supported by the compiler"
50 }
51
52 gdb_test "python print (objfile.progspace)" "<gdb\.Progspace object at .*>" \
53 "Get objfile program space"
54 gdb_test "python print (objfile.is_valid())" "True" \
55 "Get objfile validity"
56 gdb_unload
57 gdb_test "python print (objfile.is_valid())" "False" \
58 "Get objfile validity after unload"
59
60 gdb_py_test_silent_cmd "python objfile.random_attribute = 42" \
61 "Set random attribute in objfile" 1
62 gdb_test "python print (objfile.random_attribute)" "42" \
63 "Verify set of random attribute in objfile"
64
65 # Now build another copy of the testcase, this time without debug info.
66
67 if { [prepare_for_testing ${testfile}.exp ${testfile}2 ${srcfile} {nodebug ldflags=-Wl,--strip-debug}] } {
68 return -1
69 }
70
71 if ![runto_main] {
72 fail "Can't run to main"
73 return 0
74 }
75
76 gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \
77 "Get no-debug objfile file" 1
78
79 gdb_test "python print (objfile.owner)" "None" \
80 "Test owner of real objfile."
81
82 gdb_test "p main" "= {<text variable, no debug info>} $hex <main>" \
83 "print main without debug info"
84
85 gdb_py_test_silent_cmd "python objfile.add_separate_debug_file(\"${binfile}\")" \
86 "Add separate debug file file" 1
87
88 gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \
89 "Get separate debug info objfile" 1
90
91 gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \
92 "Test owner of separate debug file"
93
94 gdb_test "p main" "= {int \\(\\)} $hex <main>" \
95 "print main with debug info"
This page took 0.032077 seconds and 4 git commands to generate.