setreg.exp   [plain text]


# Copyright 2006 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.  

# Only PPC has a funky register size issue.

if ![istarget "powerpc-apple-darwin*"] {
    verbose "Skipping PPC-specific register test."
    return
}

if $tracelevel then {
        strace $tracelevel
        }

#
# test running programs
#

set prms_id 0
set bug_id 0

set testfile "setreg"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}

# 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 $"

gdb_test "break main" "Breakpoint 1 at $hex: file.*, line.*\\." "Set breakpoint on line  'good stopping point in main'"

gdb_test "run" "Starting program: $binfile *\r\n\Reading symbols for shared libraries \(\[.+\]\)+ done.*Breakpoint 1, main.*" "continue to breakpoint in main()"

# Check manual setting of a register.

gdb_test "print \$r25 = 0x1234" ".*" "set r25 to a 32-bit value"
gdb_test "print \$r26 = 0x0" ".*" "set r26 to a 32-bit value"

gdb_test "print/x \$r25" ".* = 0x1234" "check r25 value"
gdb_test "print/x \$r26" ".* = 0x0" "check r26 value"

gdb_test "print \$r25 = 0x123456789abcdef" ".*" "set r25 to a 64-bit value"

gdb_test "print/x \$r25" ".* = 0x123456789abcdef" "check r25 value"
gdb_test "print/x \$r26" ".* = 0x0" "check r26 value"

# Check setting of a 32-bit variable stored in a register.

gdb_test "print \$r14 = 0xcba98765" ".*" "set r14 to sentinel value"
gdb_test "print \$r15 = 0xdcba9876" ".*" "set r15 to sentinel value"

gdb_test "step" ".*" "init glob1"

gdb_test "print/x glob1" ".* = 0x1234" "check glob1 value"
gdb_test "print/x \$r14" ".* = 0x1234" "check r14 value"
gdb_test "print/x \$r15" ".* = 0xdcba9876" "check r15 value"

# Check setting of a 64-bit variable in a register.

gdb_test "print \$r20 = 0xcba98765" ".*" "set r20 to sentinel value"
gdb_test "print \$r21 = 0xdcba9876" ".*" "set r21 to sentinel value"

gdb_test "step" ".*" "init glob2"

gdb_test "print/x glob2" ".* = 0x123456787abcdef0" "check glob2 value"
if [target_info exists darwin64] {
    gdb_test "print/x \$r20" ".* = 0x123456787abcdef0" "check r20 value"
} else {
    gdb_test "print/x \$r20" ".* = 0x12345678" "check r20 value"
    gdb_test "print/x \$r21" ".* = 0x7abcdef0" "check r21 value"
}

gdb_test "print glob2 = 0xfedcba9876543210" ".*" "set glob2 to a 64-bit value"

gdb_test "print/x glob2" ".* = 0xfedcba9876543210" "check glob2 value after set"
if [target_info exists darwin64] {
    gdb_test "print/x \$r20" ".* = 0xfedcba9876543210" "check r20 value after set"
} else {
    gdb_test "print/x \$r20" ".* = 0xfedcba98" "check r20 value after set"
    gdb_test "print/x \$r21" ".* = 0x76543210" "check r21 value after set"
}

gdb_exit
return 0