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}/objdbg01 12set toolssubdir ${srcdir}/${subdir}/tools 13set objdbgdir ${objdir}/${subdir}/objdbg01 14set binfile ${objdbgdir}/${testfile} 15set symaddrfile ${toolssubdir}/symaddr 16 17# Create and source the file that provides information about the compiler 18# used to compile the test case. 19if [get_compiler_info ${binfile}] { 20 return -1 21} 22 23if {!$hp_aCC_compiler && !$hp_cc_compiler} { 24 return 0 25} 26 27if { [gdb_compile "${toolssubdir}/test-objdbg.cc" "${objdbgdir}/test-objdbg.o" object "debug c++ {additional_flags=-I${toolssubdir} +objdebug}"] != "" } { 28 gdb_suppress_entire_file "WARNING: +objdebug option is not supported in this compiler version, test ignored." 29} 30 31if { [gdb_compile "${srcsubdir}/x1.cc" "${objdbgdir}/x1.o" object "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } { 32 perror "Couldn't compile x1.cc" 33 return -1 34} 35 36if { [gdb_compile "${srcsubdir}/x2.cc" "${objdbgdir}/x2.o" object "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } { 37 perror "Couldn't compile x2.cc" 38 return -1 39} 40 41if { [gdb_compile "${srcsubdir}/x3.cc" "${objdbgdir}/x3.o" object "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } { 42 perror "Couldn't compile x3.cc" 43 return -1 44} 45 46if { [gdb_compile "${objdbgdir}/x1.o ${objdbgdir}/x2.o ${objdbgdir}/x3.o" "${binfile}0" executable "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } { 47 perror "Couldn't compile ${binfile}0" 48 return -1 49} 50 51if {[gdb_compile "${objdbgdir}/x3.o ${objdbgdir}/x2.o ${objdbgdir}/x1.o" "${binfile}1" executable "debug c++ {additional_flags=-I${srcsubdir} +objdebug}"] != "" } { 52 perror "Couldn't compile ${binfile}1" 53 return -1 54} 55 56# Test two executables. The first has x1.cc linked first, the second 57# has x3.cc linked first. The difference is that in the first one, 58# the Info<PP> instantiation from x1.cc is taken, in the second, its 59# from x3.cc. 60 61for {set filenum 0} {$filenum < 2} {incr filenum 1} { 62 63 # Lets test some commons 64 # Need to restart each to to make sure objects are not loaded 65 # Also cross check the address with what is actually in the 66 # object file (call the executable ${symaddrfile} to retrieve the 67 # information). 68 69 set exec_output [lindex [remote_exec build "${symaddrfile} ${binfile}${filenum} acomm"] 1] 70 regsub -all "\[\r\n\]" ${exec_output} "" exec_output 71 72 gdb_exit 73 gdb_start 74 gdb_reinitialize_dir ${srcsubdir} 75 gdb_load ${binfile}${filenum} 76 gdb_test "p &acomm" "..* = \\(int \[*\]\\) 0x${exec_output}.*" 77 78 gdb_exit 79 gdb_start 80 gdb_reinitialize_dir ${srcsubdir} 81 gdb_load ${binfile}${filenum} 82 gdb_test "b main" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file ..*/x1.cc, line 20." 83 gdb_test "run" "Starting program:.*Breakpoint \[0-9\]+, main .*/x1.cc:20.*20.*acomm.*=.*1.*" 84 gdb_test "s 1" "21.*" 85 gdb_test "p acomm" ".* = 1.*" 86 gdb_test "p &acomm" "..* = \\(int \[*\]\\) 0x${exec_output}.*" 87 88 # Step through each line. 89 # Do this three times. 90 # First round: Test that things are okay after printing commons 91 # above. 92 # Second round: Restart gdb and make sure we can walk through 93 # Third round: Do NOT restrart gdb to verify that the debug information 94 # was not messed up by loading additional object files from 95 # the first run through. 96 for {set i 0} {$i < 3} {incr i 1} { 97 if $i==1 then { 98 gdb_exit 99 gdb_start 100 gdb_reinitialize_dir ${srcsubdir} 101 gdb_load ${binfile}${filenum} 102 } 103 if $i!=2 then { 104 gdb_test "b main" \ 105 "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file ..*/x1.cc, line 20." 106 } 107 if $i!=0 then { 108 gdb_test "run" \ 109 "Starting program:.*Breakpoint \[0-9\]+, main .*/x1.cc:20.*" 110 gdb_test "s 1" "21.*" 111 } 112 gdb_test "s 1" "Info<PP>::p .*/x3.h:11.*" 113 gdb_test "s 1" "PP::print .*/x2.cc:8.*" 114 gdb_test "s 1" ".*9.*" 115 gdb_test "s 1" "Info<PP>::p .*/x3.h:12.*" 116 gdb_test "s 1" "main .*/x1.cc:22.*" 117 gdb_test "s 1" "foo .*/x3.cc:5.*" 118 gdb_test "s 1" "Info<PP>::p .*/x3.h:11.*" 119 gdb_test "s 1" "PP::print .*/x2.cc:8.*" 120 gdb_test "s 1" ".*9.*" 121 gdb_test "s 1" "Info<PP>::p .*/x3.h:12.*" 122 gdb_test "s 1" "foo .*/x3.cc:6.*" 123 gdb_test "s 1" "Info<QQ>::p .*/x3.h:11.*" 124 gdb_test "s 1" "QQ::print .*/x2.cc:13.*" 125 gdb_test "s 1" ".*14.*" 126 gdb_test "s 1" "Info<QQ>::p .*/x3.h:12.*" 127 gdb_test "s 1" "foo .*/x3.cc:7.*" 128 gdb_test "s 1" "main .*/x1.cc:24.*" 129 gdb_test "s 1" ".*25.*" 130 if [istarget "hppa64-*-*"] { 131 gdb_test "s 1" "0x\[0-9a-f\]+ in .*" 132 gdb_test "c" ".*Program exited normally.*" 133 } else { 134 gdb_test "s 1" "0x\[0-9a-f\]+ in _start .*" 135 gdb_test "s 1" ".*Program exited normally.*" 136 } 137 } 138 139 # Test various ptypes, and combinations of them 140 # Test things multiple times in each set to make sure that the debug 141 # information did not get messed up. 142 143 gdb_exit 144 gdb_start 145 gdb_reinitialize_dir ${srcsubdir} 146 gdb_load ${binfile}${filenum} 147 gdb_test "ptype QQ" "type = (class |)QQ {..*void print( |)..*}.*" 148 gdb_test "ptype PP" "type = (class |)PP {..*void print( |)..*}.*" 149 gdb_test "ptype QQ" "type = (class |)QQ {..*void print( |)..*}.*" 150 151 gdb_exit 152 gdb_start 153 gdb_reinitialize_dir ${srcsubdir} 154 gdb_load ${binfile}${filenum} 155 gdb_test "ptype PP" "type = (class |)PP {..*void print( |)..*}.*" 156 gdb_test "ptype QQ" "type = (class |)QQ {..*void print( |)..*}.*" 157 gdb_test "ptype PP" "type = (class |)PP {..*void print( |)..*}.*" 158 159 gdb_exit 160 gdb_start 161 gdb_reinitialize_dir ${srcsubdir} 162 gdb_load ${binfile}${filenum} 163 gdb_test "ptype Info<QQ>" "type = (class |)Info<QQ> {..*void p( |)..*}.*" 164 gdb_test "ptype Info<PP>" "type = (class |)Info<PP> {..*void p( |)..*}.*" 165 gdb_test "ptype Info<QQ>" "type = (class |)Info<QQ> {..*void p( |)..*}.*" 166 167 gdb_exit 168 gdb_start 169 gdb_reinitialize_dir ${srcsubdir} 170 gdb_load ${binfile}${filenum} 171 gdb_test "ptype Info<PP>" "type = (class |)Info<PP> {..*void p( |)..*}.*" 172 gdb_test "ptype Info<QQ>" "type = (class |)Info<QQ> {..*void p( |)..*}.*" 173 gdb_test "ptype Info<PP>" "type = (class |)Info<PP> {..*void p( |)..*}.*" 174 175 gdb_exit 176 gdb_start 177 gdb_reinitialize_dir ${srcsubdir} 178 gdb_load ${binfile}${filenum} 179 gdb_test "ptype Info" "type = template <..*> (class |)Info {..*}.*" 180 gdb_test "ptype Info<PP>" "type = (class |)Info<PP> {..*void p( |)..*}.*" 181 gdb_test "ptype Info<QQ>" "type = (class |)Info<QQ> {..*void p( |)..*}.*" 182 gdb_test "ptype Info" "type = template <..*> (class |)Info {..*}.*" 183 184 gdb_exit 185 gdb_start 186 gdb_reinitialize_dir ${srcsubdir} 187 gdb_load ${binfile}${filenum} 188 gdb_test "ptype class QQ" "type = (class |)QQ {..*void print( |)..*}.*" 189 gdb_test "ptype class PP" "type = (class |)PP {..*void print( |)..*}.*" 190 gdb_test "ptype class QQ" "type = (class |)QQ {..*void print( |)..*}.*" 191 192 gdb_exit 193 gdb_start 194 gdb_reinitialize_dir ${srcsubdir} 195 gdb_load ${binfile}${filenum} 196 gdb_test "ptype class PP" "type = (class |)PP {..*void print( |)..*}.*" 197 gdb_test "ptype class QQ" "type = (class |)QQ {..*void print( |)..*}.*" 198 gdb_test "ptype class PP" "type = (class |)PP {..*void print( |)..*}.*" 199 200 gdb_exit 201 gdb_start 202 gdb_reinitialize_dir ${srcsubdir} 203 gdb_load ${binfile}${filenum} 204 gdb_test "ptype class Info<QQ>" \ 205 "type = (class |)Info<QQ> {..*void p( |)..*}.*" 206 gdb_test "ptype class Info<PP>" \ 207 "type = (class |)Info<PP> {..*void p( |)..*}.*" 208 gdb_test "ptype class Info<QQ>" \ 209 "type = (class |)Info<QQ> {..*void p( |)..*}.*" 210 211 gdb_exit 212 gdb_start 213 gdb_reinitialize_dir ${srcsubdir} 214 gdb_load ${binfile}${filenum} 215 gdb_test "ptype class Info<PP>" \ 216 "type = (class |)Info<PP> {..*void p( |)..*}.*" 217 gdb_test "ptype class Info<QQ>" \ 218 "type = (class |)Info<QQ> {..*void p( |)..*}.*" 219 gdb_test "ptype class Info<PP>" \ 220 "type = (class |)Info<PP> {..*void p( |)..*}.*" 221} 222 223