# Copyright 2002
# 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@prep.ai.mit.edu

# This file was written by Jason Molenda (jmolenda@apple.com)

if ![istarget "powerpc-apple-darwin*"] {
    verbose "Skipping CFM tests."
    return
}

if $tracelevel then {
        strace $tracelevel
}

set prms_id 0
set bug_id 0

set testfile "cfm"
set binfile ${objdir}/${subdir}/${testfile}

set orig_timeout $timeout
set timeout 180

remote_exec build "sh ${srcdir}/${subdir}/cfm.sh ${srcdir}/${subdir}"

set additional_flags "-framework Carbon"
if  { [gdb_compile "${srcdir}/${subdir}/cfm.c" "${binfile}" executable {debug additional_flags=-framework\ Carbon}] != "" } {
     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_load ${binfile}

if ![runto_main] then { 
  fail "cfm tests suppressed"
  return -1
}

gdb_test "break f" ".*Breakpoint.*"
gdb_test "continue" ".*Continuing.*Reading symbols for shared libraries.*Breakpoint 2, f.*"
send_gdb "info sharedlibrary raw-cfm\n"

# The following match string created with this:
# #! /bin/sh
# 
# echo -n "  " -re \"
# i=2
# while [ $i -lt 12 ]
# do
#   echo -n ".* $i.cfm *- \$hex *cfm . N \\\"/tmp/cfm/$i.cfm\\\""
#   i=`expr $i + 1`
# done
# i=60
# while [ $i -lt 65 ]
# do
#   echo -n ".* $i.cfm *- \$hex *cfm . N \\\"/tmp/cfm/$i.cfm\\\""
#   i=`expr $i + 1`
# done
# echo \" \{

# I skip the middle bits because something (expect?  tcl?  Mach?) wasn't
# working when I had every one of the 65 CFM modules listed..

global gdb_prompt
gdb_expect {
   -re ".* 2.cfm *- $hex *cfm . N \"/tmp/cfm/2.cfm\".* 3.cfm *- $hex *cfm . N \"/tmp/cfm/3.cfm\".* 4.cfm *- $hex *cfm . N \"/tmp/cfm/4.cfm\".* 5.cfm *- $hex *cfm . N \"/tmp/cfm/5.cfm\".* 6.cfm *- $hex *cfm . N \"/tmp/cfm/6.cfm\".* 62.cfm *- $hex *cfm . N \"/tmp/cfm/62.cfm\".* 63.cfm *- $hex *cfm . N \"/tmp/cfm/63.cfm\".* 64.cfm *- $hex *cfm . N \"/tmp/cfm/64.cfm\"" {
    pass "info sharedlibrary raw-cfm"
  }
  -re "$gdb_prompt $" {fail "info sharedlibrary raw-cfm" }
  timeout {fail "(timeout) info sharedlibrary raw-cfm" }
}

set timeout $orig_timeout
remote_exec build "rm -rf /tmp/cfm"

gdb_exit
return 0
