# Copyright 2004 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. # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@gnu.org # This file is part of the gdb testsuite. if $tracelevel { strace $tracelevel } # # Test for backtrace past main. # set prms_id 0 set bug_id 0 # should 4 digits or less set subr_depth 100 set testfile "backtrace" set srcfile "$subdir/$testfile.c" set escapedsrcfile [string_to_regexp "./$srcfile"] set binfile ${objdir}/${subdir}/${testfile} # Generate the 'c' program. set src_out [open $srcfile "w"] puts $src_out "/* Copyright 2004 Free Software Foundation, Inc. */\n" puts $src_out "/* This file is used by 'backtrace.exp', part of the gdb testsuite. */\n" puts $src_out "#include \n" puts $src_out [format "void deep_sub_%04d (int up_count, int down_count)" $subr_depth] puts $src_out "{\n printf (\"At the bottom\\n\");\n}\n" for {set i [expr $subr_depth - 1]} {$i > 0} {incr i -1} { puts $src_out [format "void deep_sub_%04d (int up_count, int down_count)" $i] puts $src_out [format "{\n deep_sub_%04d (++up_count, --down_count);\n}\n" [expr $i + 1]] } puts $src_out [format "int main()\n{\n deep_sub_%04d (0, $subr_depth);\n return 0;\n}" 1] close $src_out # Compile the 'c' program. if { [gdb_compile "${srcdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." } # Reset and start GDB gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load ${binfile} set test "backtrace past main" # Set a breakpoint at the deepest subroutine. gdb_test [format "break deep_sub_%04d" $subr_depth] "Breakpoint 1 at $hex: file $escapedsrcfile, line $decimal." "$test" # Run the test program. gdb_test "run" "Starting program:.*Breakpoint 1,.*printf \\(\"At the bottom\\\\n\"\\);" "$test" # Do the backtrace. (lots of output) set first_line [format "#0 deep_sub_%04d \\(up_count=%d, down_count=1\\) at $escapedsrcfile:$decimal" $subr_depth [expr $subr_depth - 1]] #$decimal $hex in deep_sub_$decimal .up_count=$decimal, down_count=$decimal) at ./gdb.base/backtrace.c:489 set middle_lines "#$decimal +$hex in deep_sub_$decimal \\(up_count=$decimal, down_count=$decimal\\) at $escapedsrcfile:$decimal" set last_line [format "#%d +$hex in main .. at $escapedsrcfile:$decimal\r\n" $subr_depth] gdb_test_multiple "backtrace" "$test" { -re "$first_line\r\n($middle_lines\r\n)+$last_line$gdb_prompt $" { pass "$test" } }