1# Test reading debug information from in object files.
2
3if { [skip_hp_tests] } { continue }
4
5if { ![istarget "hppa*-*-hpux*"] } {
6    verbose "HPUX test ignored for non-hppa targets."
7    return 0
8}
9
10set testfile "test"
11set srcsubdir ${srcdir}/${subdir}/objdbg03
12set objdbgdir ${objdir}/${subdir}/objdbg03
13set binfile ${objdbgdir}/${testfile}
14set toolssubdir ${srcdir}/${subdir}/tools
15if [istarget "hppa64-*-*"] {
16  set symaddrfile ${toolssubdir}/symaddr.pa64
17} else {
18  set symaddrfile ${toolssubdir}/symaddr
19}
20
21# Create and source the file that provides information about the compiler
22# used to compile the test case.
23if [get_compiler_info ${binfile}] {
24    return -1
25}
26
27if {!$hp_aCC_compiler && !$hp_cc_compiler} {
28  return 0
29}
30
31if { [gdb_compile "${toolssubdir}/test-objdbg.cc" "${objdbgdir}/test-objdbg.o" object "debug c++ {additional_flags=-I${toolssubdir} +objdebug}"] != "" } {
32    gdb_suppress_entire_file "WARNING: +objdebug option is not supported in this compiler version, test ignored."
33}
34
35if { [gdb_compile "${srcsubdir}/x1.cc" "${objdbgdir}/x1.o" object "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } {
36    perror "Couldn't compile x1.cc"
37    return -1
38}
39
40if { [gdb_compile "${srcsubdir}/x2.cc" "${objdbgdir}/x2.o" object "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } {
41    perror "Couldn't compile x2.cc"
42    return -1
43}
44
45if { [gdb_compile "${srcsubdir}/x3.cc" "${objdbgdir}/x3.o" object "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } {
46    perror "Couldn't compile x3.cc"
47    return -1
48}
49
50if { [gdb_compile "${objdbgdir}/x1.o ${objdbgdir}/x2.o ${objdbgdir}/x3.o" "${binfile}" executable "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } {
51    perror "Couldn't compile ${binfile}"
52    return -1
53}
54
55#
56# Test some normal commons
57#
58
59# Print the types
60
61gdb_exit
62gdb_start
63gdb_reinitialize_dir ${srcsubdir}
64gdb_load ${binfile}
65
66gdb_test "ptype common1" "type = int"
67gdb_test "ptype common2" "type = int"
68gdb_test "ptype common3" "type = int"
69gdb_test "ptype data1" "type = int"
70gdb_test "ptype data2" "type = int"
71gdb_test "ptype data3" "type = int"
72gdb_test "ptype common11" "type = int"
73gdb_test "ptype common10" "type = int"
74gdb_test "ptype data10" "type = int"
75gdb_test "ptype data11" "type = int"
76
77# Print the values
78
79gdb_exit
80gdb_start
81gdb_reinitialize_dir ${srcsubdir}
82gdb_load ${binfile}
83
84gdb_test "b main" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file ..*/x1.cc, line 11."
85gdb_test "run" "Starting program:.*Breakpoint \[0-9\]+, main .*/x1.cc:11.*"
86gdb_test "p data1" "..* = 1"
87gdb_test "p data2" "..* = 2"
88gdb_test "p data3" "..* = 3"
89gdb_test "p data10" "..* = 10"
90gdb_test "p data11" "..* = 11"
91gdb_test "n" ".*12.*"
92gdb_test "p common11" "..* = 11"
93
94gdb_test "s 1" "foo .*/x3.cc:15.*"
95gdb_test "s 4" ".*20.*"
96gdb_test "p data4" "..* = 4"
97gdb_test "p common4" "..* = 4"
98gdb_test "n" ".*21.*"
99
100gdb_test "n" "main .*/x1.cc:14.*"
101gdb_test "p common1" "..* = 1"
102gdb_test "p common2" "..* = 2"
103gdb_test "p common3" "..* = 3"
104
105# Verify that addresses match those in the executable
106
107gdb_exit
108gdb_start
109gdb_reinitialize_dir ${srcsubdir}
110gdb_load ${binfile}
111
112set exec_output_data1 [lindex [remote_exec build "${symaddrfile} ${binfile} data1"] 1]
113regsub -all "\[\r\n\]" ${exec_output_data1} "" exec_output_data1
114
115set exec_output_data2 [lindex [remote_exec build "${symaddrfile} ${binfile} data2"] 1]
116regsub -all "\[\r\n\]" ${exec_output_data2} "" exec_output_data2
117
118set exec_output_data3 [lindex [remote_exec build "${symaddrfile} ${binfile} data3"] 1]
119regsub -all "\[\r\n\]" ${exec_output_data3} "" exec_output_data3
120
121set exec_output_data10 [lindex [remote_exec build "${symaddrfile} ${binfile} data10"] 1]
122regsub -all "\[\r\n\]" ${exec_output_data10} "" exec_output_data10
123
124set exec_output_data11 [lindex [remote_exec build "${symaddrfile} ${binfile} data11"] 1]
125regsub -all "\[\r\n\]" ${exec_output_data11} "" exec_output_data11
126
127set exec_output_common1 [lindex [remote_exec build "${symaddrfile} ${binfile} common1"] 1]
128regsub -all "\[\r\n\]" ${exec_output_common1} "" exec_output_common1
129
130set exec_output_common2 [lindex [remote_exec build "${symaddrfile} ${binfile} common2"] 1]
131regsub -all "\[\r\n\]" ${exec_output_common2} "" exec_output_common2
132
133set exec_output_common3 [lindex [remote_exec build "${symaddrfile} ${binfile} common3"] 1]
134regsub -all "\[\r\n\]" ${exec_output_common3} "" exec_output_common3
135
136set exec_output_common10 [lindex [remote_exec build "${symaddrfile} ${binfile} common10"] 1]
137regsub -all "\[\r\n\]" ${exec_output_common10} "" exec_output_common10
138
139set exec_output_common11 [lindex [remote_exec build "${symaddrfile} ${binfile} common11"] 1]
140regsub -all "\[\r\n\]" ${exec_output_common11} "" exec_output_common11
141
142if [istarget "hppa64-*-*"] {
143    gdb_test "p &data1" "..* = \\(int \[*\]\\) ${exec_output_data1}"
144    gdb_test "p &data2" "..* = \\(int \[*\]\\) ${exec_output_data2}"
145    gdb_test "p &data3" "..* = \\(int \[*\]\\) ${exec_output_data3}"
146    gdb_test "p &data10" "..* = \\(int \[*\]\\) ${exec_output_data10}"
147    gdb_test "p &data11" "..* = \\(int \[*\]\\) ${exec_output_data11}"
148    gdb_test "p &common1" "..* = \\(int \[*\]\\) ${exec_output_common1}"
149    gdb_test "p &common2" "..* = \\(int \[*\]\\) ${exec_output_common2}"
150    gdb_test "p &common3" "..* = \\(int \[*\]\\) ${exec_output_common3}"
151    gdb_test "p &common10" "..* = \\(int \[*\]\\) ${exec_output_common10}"
152    gdb_test "p &common11" "..* = \\(int \[*\]\\) ${exec_output_common11}"
153} else {
154    gdb_test "p &data1" "..* = \\(int \[*\]\\) 0x${exec_output_data1}"
155    gdb_test "p &data2" "..* = \\(int \[*\]\\) 0x${exec_output_data2}"
156    gdb_test "p &data3" "..* = \\(int \[*\]\\) 0x${exec_output_data3}"
157    gdb_test "p &data10" "..* = \\(int \[*\]\\) 0x${exec_output_data10}"
158    gdb_test "p &data11" "..* = \\(int \[*\]\\) 0x${exec_output_data11}"
159    gdb_test "p &common1" "..* = \\(int \[*\]\\) 0x${exec_output_common1}"
160    gdb_test "p &common2" "..* = \\(int \[*\]\\) 0x${exec_output_common2}"
161    gdb_test "p &common3" "..* = \\(int \[*\]\\) 0x${exec_output_common3}"
162    gdb_test "p &common10" "..* = \\(int \[*\]\\) 0x${exec_output_common10}"
163    gdb_test "p &common11" "..* = \\(int \[*\]\\) 0x${exec_output_common11}"
164}
165