| # Copyright 2005 Free Software Foundation, Inc. |
| |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 2 of the License, or |
| # (at your option) any later version. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| # GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with this program; if not, write to the Free Software |
| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| |
| if $tracelevel then { |
| strace $tracelevel |
| } |
| |
| # |
| # This tests gdb's handling of debug information stored in .o files |
| # with -gdwarf-2. Particularly the case where some of the .o files |
| # have been deleted. |
| # |
| |
| set prms_id 0 |
| set bug_id 0 |
| |
| set using_dsym 0 |
| foreach x $board_variant_list { |
| if {$x == ""} { |
| continue |
| } |
| switch $x { |
| dsym {set using_dsym 1} |
| default {} |
| } |
| } |
| |
| if {$using_dsym} { |
| gdb_suppress_entire_file "This test doesn't work when forcing dsym testing" |
| return 0 |
| } |
| |
| set test_name "debug-in-ofile" |
| |
| set testfile "debug-in-ofile" |
| |
| set binfile "${objdir}/${subdir}/${testfile}" |
| |
| set additional_flags additional_flags=-gdwarf-2 |
| |
| |
| # Build all with dwarf |
| |
| foreach {src} {main one two three four five six} { |
| if { [gdb_compile "$srcdir/$subdir/$src.c" "$objdir/$subdir/$src.o" object $additional_flags] != "" } { |
| gdb_suppress_entire_file "Testcase compile failed for $test_name, so all tests in this file will automatically fail." |
| } |
| file delete -force $objdir/$subdir/$src.o.hidden |
| } |
| |
| set intermediate_obj $objdir/$subdir/dbg-in-ofile.o |
| file delete -force $intermediate_obj |
| file delete -force $intermediate_obj.hidden |
| set command "ld -r \"$objdir/$subdir/one.o\" \"$objdir/$subdir/three.o\" -o \"$intermediate_obj\"" |
| |
| set status [remote_exec host $command] |
| if {[lindex $status 0] != 0} { |
| puts [lindex $status 1] |
| gdb_suppress_entire_file "Testcase ld -r failed for $test_name, so all tests in this file will automatically fail." |
| } |
| |
| set intermediate_ar $objdir/$subdir/dbg-in-ofile.a |
| file delete -force $intermediate_ar |
| file delete -force $intermediate_ar.hidden |
| set command "ar -c -q \"$intermediate_ar\" \"$objdir/$subdir/two.o\" \"$objdir/$subdir/five.o\"" |
| |
| set status [remote_exec host $command] |
| if {[lindex $status 0] != 0} { |
| puts [lindex $status 1] |
| gdb_suppress_entire_file "Testcase ld -r failed for $test_name, so all tests in this file will automatically fail." |
| } |
| |
| set command "ranlib \"$intermediate_ar\"" |
| |
| set status [remote_exec host $command] |
| if {[lindex $status 0] != 0} { |
| puts [lindex $status 1] |
| gdb_suppress_entire_file "Testcase ld -r failed for $test_name, so all tests in this file will automatically fail." |
| } |
| |
| set additional_flags additional_flags=-gdwarf-2 |
| if { [gdb_compile "$objdir/$subdir/main.o $objdir/$subdir/four.o $intermediate_obj $intermediate_ar $objdir/$subdir/six.o" "${binfile}" executable $additional_flags] != "" } { |
| gdb_suppress_entire_file "Testcase compile failed for $test_name, so all tests in this file will automatically fail." |
| } |
| |
| # This sets breakpoints on the functions "my_one" through "six" and |
| # checks to make sure that the breakpoint type is the same as $pbt_ptr(function). |
| # Then it continues to each of the breakpoints, and makes sure we get there and |
| # can do a backtrace. |
| |
| proc do_tests {title bpt_ptr} { |
| global srcdir objdir subdir binfile gdb_prompt hex |
| upvar $bpt_ptr expected_bpt |
| |
| # Start with a fresh gdb |
| gdb_exit |
| gdb_start |
| gdb_reinitialize_dir $srcdir/$subdir |
| gdb_file_cmd "${binfile}" |
| |
| send_gdb "set width 0\n" |
| gdb_expect -re "$gdb_prompt $" |
| runto_main |
| |
| foreach function {my_one my_two my_three my_four my_five my_six} { |
| set breakpoints($function) [gdb_breakpoint_2 $function] |
| if {[lindex $breakpoints($function) 0] eq [lindex $expected_bpt($function) 0]} { |
| pass "$title - Setting bpt at $function" |
| } else { |
| fail "$title - Setting bpt at $function" |
| } |
| } |
| |
| foreach function {my_one my_two my_three my_four my_five my_six} { |
| set type [lindex $breakpoints($function) 0] |
| switch $type { |
| line {gdb_continue $function} |
| address {gdb_test "continue" \ |
| ".*Breakpoint [lindex $breakpoints($function) 1], $hex in $function \\\(\\\)" \ |
| "$title: Continue to $function"} |
| error {} |
| } |
| # We aren't really checking the backtrace return, but we used to crash |
| # when we backtrace, so I want to make sure we don't do that... |
| gdb_test backtrace ".*" "$title: successful backtrace at $function" |
| } |
| } |
| |
| |
| proc hide_file {args} { |
| global objdir subdir |
| foreach file $args { |
| file rename $objdir/$subdir/$file $objdir/$subdir/$file.hidden |
| } |
| } |
| |
| proc reveal_file {args} { |
| global objdir subdir |
| foreach file $args { |
| file rename $objdir/$subdir/$file.hidden $objdir/$subdir/$file |
| } |
| } |
| |
| # Okay, now we are going to remove some of the .o files |
| |
| hide_file one.o six.o |
| array set expected_breakpoints { |
| my_one address |
| my_two line |
| my_three line |
| my_four line |
| my_five line |
| my_six address |
| } |
| do_tests "missing one.o four.o" expected_breakpoints |
| reveal_file one.o six.o |
| |
| hide_file dbg-in-ofile.a |
| array set expected_breakpoints { |
| my_one line |
| my_two address |
| my_three line |
| my_four line |
| my_five address |
| my_six line |
| } |
| do_tests "missing .a file" expected_breakpoints |
| reveal_file dbg-in-ofile.a |
| |
| # You have to hide the .o files as well, turns out |
| # since the debug info is not in the ld -r file, it |
| # really isn't used for debugging. |
| |
| hide_file dbg-in-ofile.o one.o three.o |
| array set expected_breakpoints { |
| my_one address |
| my_two line |
| my_three address |
| my_four line |
| my_five line |
| my_six line |
| } |
| do_tests "missing ld -r file" expected_breakpoints |
| reveal_file dbg-in-ofile.o one.o three.o |
| |
| # Finally, build a dSYM file, and make sure we just ignore all the missing files. |
| |
| set command "dsymutil $binfile" |
| |
| set status [remote_exec host $command] |
| if {[lindex $status 0] != 0} { |
| puts [lindex $status 1] |
| fail "Building dSYM file" |
| } else { |
| pass "Building dSYM file" |
| |
| hide_file one.o six.o |
| array set expected_breakpoints { |
| my_one line |
| my_two line |
| my_three line |
| my_four line |
| my_five line |
| my_six line |
| } |
| do_tests "Using dSYM" expected_breakpoints |
| reveal_file one.o six.o |
| file delete -force $binfile.dSYM |
| } |
| |
| return 0 |
| |
| |