OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.base/] [shreloc.exp] - Diff between revs 24 and 157

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 24 Rev 157
# Copyright (C) 2003, 2005, 2007, 2008 Free Software Foundation, Inc.
# Copyright (C) 2003, 2005, 2007, 2008 Free Software Foundation, Inc.
#
#
# This program is free software; you can redistribute it and/or modify
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
# along with this program.  If not, see .
#
#
# Tests for shared object file relocation. If two shared objects have
# Tests for shared object file relocation. If two shared objects have
# the same load address (actually, overlapping load spaces), one of
# the same load address (actually, overlapping load spaces), one of
# them gets relocated at load-time. Check that gdb gets the right
# them gets relocated at load-time. Check that gdb gets the right
# values for the debugging and minimal symbols.
# values for the debugging and minimal symbols.
if {[skip_shlib_tests]} {
if {[skip_shlib_tests]} {
    return 0
    return 0
}
}
if $tracelevel then {
if $tracelevel then {
    strace $tracelevel
    strace $tracelevel
}
}
#
#
# This file uses shreloc.c, shreloc1.c and shreloc2.c
# This file uses shreloc.c, shreloc1.c and shreloc2.c
#
#
set prms_id 0
set prms_id 0
set bug_id 0
set bug_id 0
set workdir ${objdir}/${subdir}
set workdir ${objdir}/${subdir}
set testfile "shreloc"
set testfile "shreloc"
set libfile1 "shreloc1"
set libfile1 "shreloc1"
set libfile2 "shreloc2"
set libfile2 "shreloc2"
set srcfile $srcdir/$subdir/$testfile.c
set srcfile $srcdir/$subdir/$testfile.c
set lib1src $srcdir/$subdir/$libfile1.c
set lib1src $srcdir/$subdir/$libfile1.c
set lib2src $srcdir/$subdir/$libfile2.c
set lib2src $srcdir/$subdir/$libfile2.c
set binfile $objdir/$subdir/$testfile
set binfile $objdir/$subdir/$testfile
set lib1_sl $objdir/$subdir/$libfile1.sl
set lib1_sl $objdir/$subdir/$libfile1.sl
set lib2_sl $objdir/$subdir/$libfile2.sl
set lib2_sl $objdir/$subdir/$libfile2.sl
if [get_compiler_info ${binfile}] {
if [get_compiler_info ${binfile}] {
    return -1
    return -1
}
}
set lib_opts "debug"
set lib_opts "debug"
set exec_opts [list debug shlib=$lib1_sl shlib=$lib2_sl]
set exec_opts [list debug shlib=$lib1_sl shlib=$lib2_sl]
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
    lappend lib_opts "ldflags=-Wl,--image-base,0x04000000"
    lappend lib_opts "ldflags=-Wl,--image-base,0x04000000"
}
}
if [test_compiler_info "xlc-*"] {
if [test_compiler_info "xlc-*"] {
    # IBM's xlc compiler does not add static variables to the ELF symbol
    # IBM's xlc compiler does not add static variables to the ELF symbol
    # table by default.  We need this option to make the variables show
    # table by default.  We need this option to make the variables show
    # up in "maint print msymbols".
    # up in "maint print msymbols".
    lappend lib_opts "additional_flags=-qstatsym"
    lappend lib_opts "additional_flags=-qstatsym"
}
}
if { [gdb_compile_shlib $lib1src $lib1_sl $lib_opts] != ""} {
if { [gdb_compile_shlib $lib1src $lib1_sl $lib_opts] != ""} {
    untested "Could not build $lib1_sl."
    untested "Could not build $lib1_sl."
    return -1
    return -1
} elseif { [gdb_compile_shlib $lib2src $lib2_sl $lib_opts] != ""} {
} elseif { [gdb_compile_shlib $lib2src $lib2_sl $lib_opts] != ""} {
    untested "Could not build $lib1_s2."
    untested "Could not build $lib1_s2."
    return -1
    return -1
} elseif { [gdb_compile $srcfile $binfile executable $exec_opts] != ""} {
} elseif { [gdb_compile $srcfile $binfile executable $exec_opts] != ""} {
    untested "Could not build $binfile."
    untested "Could not build $binfile."
    return -1
    return -1
}
}
# Start with a fresh gdb.
# Start with a fresh gdb.
gdb_exit
gdb_exit
gdb_start
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${workdir}/shreloc
gdb_load ${workdir}/shreloc
gdb_load_shlibs $lib1_sl $lib2_sl
gdb_load_shlibs $lib1_sl $lib2_sl
# Load up the shared objects
# Load up the shared objects
if ![runto_main] then {
if ![runto_main] then {
    fail "Can't run to main"
    fail "Can't run to main"
    return 0
    return 0
}
}
proc get_var_address { var } {
proc get_var_address { var } {
  global gdb_prompt hex
  global gdb_prompt hex
  send_gdb "print &${var}\n"
  send_gdb "print &${var}\n"
  # Match output like:
  # Match output like:
  # $1 = (int *) 0x0
  # $1 = (int *) 0x0
  # $5 = (int (*)()) 0
  # $5 = (int (*)()) 0
  # $6 = (int (*)()) 0x24 
  # $6 = (int (*)()) 0x24 
  gdb_expect {
  gdb_expect {
    -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
    -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
        {
        {
          pass "get address of ${var}"
          pass "get address of ${var}"
          if { $expect_out(1,string) == "0" } {
          if { $expect_out(1,string) == "0" } {
            return "0x0"
            return "0x0"
          } else {
          } else {
            return $expect_out(1,string)
            return $expect_out(1,string)
          }
          }
        }
        }
    -re "${gdb_prompt} $"
    -re "${gdb_prompt} $"
        { fail "get address of ${var} (unknown output)" }
        { fail "get address of ${var} (unknown output)" }
    timeout
    timeout
        { fail "get address of ${var} (timeout)" }
        { fail "get address of ${var} (timeout)" }
  }
  }
  return ""
  return ""
}
}
#
#
# Check debugging symbol relocations
# Check debugging symbol relocations
#
#
# Check extern function for relocation
# Check extern function for relocation
set fn_1_addr [get_var_address fn_1]
set fn_1_addr [get_var_address fn_1]
set fn_2_addr [get_var_address fn_2]
set fn_2_addr [get_var_address fn_2]
if { "${fn_1_addr}" == "${fn_2_addr}" } {
if { "${fn_1_addr}" == "${fn_2_addr}" } {
  fail "relocated extern functions have different addresses"
  fail "relocated extern functions have different addresses"
} else {
} else {
  pass "relocated extern functions have different addresses"
  pass "relocated extern functions have different addresses"
}
}
# Check extern var for relocation
# Check extern var for relocation
set extern_var_1_addr [get_var_address extern_var_1]
set extern_var_1_addr [get_var_address extern_var_1]
set extern_var_2_addr [get_var_address extern_var_2]
set extern_var_2_addr [get_var_address extern_var_2]
if { "${extern_var_1_addr}" == "${extern_var_2_addr}" } {
if { "${extern_var_1_addr}" == "${extern_var_2_addr}" } {
  fail "relocated extern variables have different addresses"
  fail "relocated extern variables have different addresses"
} else {
} else {
  pass "relocated extern variables have different addresses"
  pass "relocated extern variables have different addresses"
}
}
# Check static var for relocation
# Check static var for relocation
set static_var_1_addr [get_var_address static_var_1]
set static_var_1_addr [get_var_address static_var_1]
set static_var_2_addr [get_var_address static_var_2]
set static_var_2_addr [get_var_address static_var_2]
if { "${static_var_1_addr}" == "${static_var_2_addr}" } {
if { "${static_var_1_addr}" == "${static_var_2_addr}" } {
  fail "relocated static variables have different addresses"
  fail "relocated static variables have different addresses"
} else {
} else {
  pass "relocated static variables have different addresses"
  pass "relocated static variables have different addresses"
}
}
#
#
# Check minimal symbol relocations
# Check minimal symbol relocations
#
#
proc send_gdb_discard { command } {
proc send_gdb_discard { command } {
    # Send a command to gdb and discard output up to the next prompt
    # Send a command to gdb and discard output up to the next prompt
    global gdb_prompt
    global gdb_prompt
    send_gdb "${command}\n"
    send_gdb "${command}\n"
    # Discard output
    # Discard output
    gdb_expect {
    gdb_expect {
        -re ".*\[\r\n]+${gdb_prompt} $" {
        -re ".*\[\r\n]+${gdb_prompt} $" {
            return 1
            return 1
        }
        }
        timeout {
        timeout {
            fail "{$command} (timeout)"
            fail "{$command} (timeout)"
            return 0
            return 0
        }
        }
    }
    }
}
}
proc get_msym_addrs { var msymfile } {
proc get_msym_addrs { var msymfile } {
    # Extract the list of values for symbols matching var in the
    # Extract the list of values for symbols matching var in the
    # minimal symbol output file
    # minimal symbol output file
    global gdb_prompt hex
    global gdb_prompt hex
    set result ""
    set result ""
    send_gdb "shell grep -E \" ${var}(\[ \t\]+.*)?\$\" ${msymfile}\n"
    send_gdb "shell grep -E \" ${var}(\[ \t\]+.*)?\$\" ${msymfile}\n"
    while 1 {
    while 1 {
        gdb_expect {
        gdb_expect {
            -re "\[\[\]\[ 0-9\]+\] . (${hex}) ${var}(\[ \t\]+\[^\r\n\]*)?\[\r\n\]+" {
            -re "\[\[\]\[ 0-9\]+\] . (${hex}) ${var}(\[ \t\]+\[^\r\n\]*)?\[\r\n\]+" {
                set result [concat $result $expect_out(1,string)]
                set result [concat $result $expect_out(1,string)]
            }
            }
            -re "$gdb_prompt $" {
            -re "$gdb_prompt $" {
                pass "get_msym_addrs ${var}"
                pass "get_msym_addrs ${var}"
                return "${result}"
                return "${result}"
            }
            }
            -re "\[^\r\n\]*\[\r\n\]+" {
            -re "\[^\r\n\]*\[\r\n\]+" {
                # Skip
                # Skip
            }
            }
            timeout {
            timeout {
                fail "get_msym_addrs ${var} (timeout)"
                fail "get_msym_addrs ${var} (timeout)"
                return -1
                return -1
            }
            }
        }
        }
    }
    }
}
}
proc check_same {var msymfile} {
proc check_same {var msymfile} {
    # Check that the minimal symbol values matching var are the same
    # Check that the minimal symbol values matching var are the same
    set len [llength [lsort -unique [get_msym_addrs "${var}" "${msymfile}"]]]
    set len [llength [lsort -unique [get_msym_addrs "${var}" "${msymfile}"]]]
    if { $len == 1 } {
    if { $len == 1 } {
        return 1
        return 1
    } else {
    } else {
        return 0
        return 0
    }
    }
}
}
proc check_different {var msymfile} {
proc check_different {var msymfile} {
    # Check that the minimal symbol values matching var are different
    # Check that the minimal symbol values matching var are different
    set addr_list [lsort [get_msym_addrs "${var}" "${msymfile}"]]
    set addr_list [lsort [get_msym_addrs "${var}" "${msymfile}"]]
    set prev ""
    set prev ""
    if { [llength ${addr_list}] < 2 } {
    if { [llength ${addr_list}] < 2 } {
        return 0
        return 0
    }
    }
    foreach addr ${addr_list} {
    foreach addr ${addr_list} {
        if { ${prev} == ${addr} } {
        if { ${prev} == ${addr} } {
          return 0
          return 0
        }
        }
        set prev ${addr}
        set prev ${addr}
    }
    }
    return 1
    return 1
}
}
set msymfile "${workdir}/shreloc.txt"
set msymfile "${workdir}/shreloc.txt"
if [send_gdb_discard "maint print msymbols ${msymfile}"] {
if [send_gdb_discard "maint print msymbols ${msymfile}"] {
    if {[check_different "static_var_\[12\]" "${msymfile}"]} {
    if {[check_different "static_var_\[12\]" "${msymfile}"]} {
        pass "(msymbol) relocated static vars have different addresses"
        pass "(msymbol) relocated static vars have different addresses"
    } else {
    } else {
        fail "(msymbol) relocated static vars have different addresses"
        fail "(msymbol) relocated static vars have different addresses"
    }
    }
    if {[check_different "extern_var_\[12\]" "${msymfile}"]} {
    if {[check_different "extern_var_\[12\]" "${msymfile}"]} {
        pass "(msymbol) relocated extern vars have different addresses"
        pass "(msymbol) relocated extern vars have different addresses"
    } else {
    } else {
        fail "(msymbol) relocated extern vars have different addresses"
        fail "(msymbol) relocated extern vars have different addresses"
    }
    }
    if {[check_different "fn_\[12\]" "${msymfile}"]} {
    if {[check_different "fn_\[12\]" "${msymfile}"]} {
        pass "(msymbol) relocated functions have different addresses"
        pass "(msymbol) relocated functions have different addresses"
    } else {
    } else {
        fail "(msymbol) relocated functions have different addresses"
        fail "(msymbol) relocated functions have different addresses"
    }
    }
}
}
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
    #
    #
    # We know the names of some absolute symbols included in the
    # We know the names of some absolute symbols included in the
    # portable-executable (DLL) format. Check that they didn't get
    # portable-executable (DLL) format. Check that they didn't get
    # relocated.
    # relocated.
    #
    #
    # A better approach would be include absolute symbols via the assembler.
    # A better approach would be include absolute symbols via the assembler.
    #
    #
    if {[check_same "_minor_os_version__" "${msymfile}"]} {
    if {[check_same "_minor_os_version__" "${msymfile}"]} {
        pass "Absolute symbols not relocated"
        pass "Absolute symbols not relocated"
    } else {
    } else {
        fail "Absolute symbols not relocated"
        fail "Absolute symbols not relocated"
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.