This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/testsuite] gdb_file_cmd: enhance return value


This patch changes gdb_file_cmd to return more information in its
return value.  The new information will be used in gdb.gdb/*.exp
to distinguish the case where the new file has no debugging symbols.

Old return value:

     0  success
    -1  failure

New return value:

    { "" }          success
    { "" nodebug }  success, and the new file has no debug info
    { "..." }       failure, the string is an error message

Very few callers check the return value of gdb_file_cmd,
so very little change is needed for this.

Tested on native i686-pc-linux-gnu with the usual four
gcc's (2.95.3 3.3.3 3.4.1 HEAD) and dwarf-2/stabs+.

Manoj, I used your test for "no debugging symbols found",
but did not add any caller code to gdb.gdb/*.exp.

I'll leave this up for comments for 24 hours and then commit it.

2004-08-27  Michael Chastain  <mec.gnu@mindspring.com>

	With code from Manoj Iyer <manjo@austin.ibm.com>:
	* lib/gdb.exp (gdb_file_cmd): Return more information in the
	return value.  Add an arm for "no debugging symbols found".
	Change a stray "error" to "perror".
	(gdb_run_cmd): Adapt to new return value.
	* gdb.base/remote.exp: Adapt to new return value.
	* gdb.gdb/complaints.exp: Likewise.
	* gdb.gdb/observer.exp: Likewise.
	* gdb.gdb/selftest.exp: Likewise.
	* gdb.gdb/xfullpath.exp: Likewise.

Index: lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.56
diff -c -3 -p -r1.56 gdb.exp
*** lib/gdb.exp	23 Aug 2004 13:43:15 -0000	1.56
--- lib/gdb.exp	27 Aug 2004 23:36:10 -0000
*************** proc gdb_run_cmd {args} {
*** 180,186 ****
  	if [target_info exists gdb,do_reload_on_run] {
  	    # Specifying no file, defaults to the executable
  	    # currently being debugged.
! 	    if { [gdb_load ""] < 0 } {
  		return;
  	    }
  	    send_gdb "continue\n";
--- 180,187 ----
  	if [target_info exists gdb,do_reload_on_run] {
  	    # Specifying no file, defaults to the executable
  	    # currently being debugged.
! 	    set status [gdb_load ""]
! 	    if { [lindex $status 0] != "" } {
  		return;
  	    }
  	    send_gdb "continue\n";
*************** proc gdb_run_cmd {args} {
*** 225,231 ****
  		    send_gdb "y\n"
  		}
  		-re "The program is not being run.*$gdb_prompt $" {
! 		    if { [gdb_load ""] < 0 } {
  			return;
  		    }
  		    send_gdb "jump *$start\n";
--- 226,233 ----
  		    send_gdb "y\n"
  		}
  		-re "The program is not being run.*$gdb_prompt $" {
! 		    set status [gdb_load ""]
! 		    if { [lindex $status 0] != ""] } {
  			return;
  		    }
  		    send_gdb "jump *$start\n";
*************** proc gdb_run_cmd {args} {
*** 247,253 ****
      }
  
      if [target_info exists gdb,do_reload_on_run] {
! 	if { [gdb_load ""] < 0 } {
  	    return;
  	}
      }
--- 249,256 ----
      }
  
      if [target_info exists gdb,do_reload_on_run] {
! 	set status [gdb_load ""]
! 	if { [lindex $status 0] != "" } {
  	    return;
  	}
      }
*************** proc default_gdb_exit {} {
*** 953,987 ****
      unset gdb_spawn_id
  }
  
  #
! # load a file into the debugger.
! # return a -1 if anything goes wrong.
  #
  proc gdb_file_cmd { arg } {
      global verbose
-     global loadpath
-     global loadfile
      global GDB
-     global gdb_prompt
-     upvar timeout timeout
  
      if [is_remote host] {
! 	set arg [remote_download host $arg];
  	if { $arg == "" } {
! 	    error "download failed"
! 	    return -1;
  	}
      }
  
      send_gdb "file $arg\n"
      gdb_expect 120 {
          -re "Reading symbols from.*done.*$gdb_prompt $" {
              verbose "\t\tLoaded $arg into the $GDB"
!             return 0
!         }
!         -re "has no symbol-table.*$gdb_prompt $" {
!             perror "$arg wasn't compiled with \"-g\""
!             return -1
          }
          -re "A program is being debugged already.*Kill it.*y or n. $" {
              send_gdb "y\n"
--- 956,1004 ----
      unset gdb_spawn_id
  }
  
+ # Load a file into the debugger.
+ # The return value is a list with the following information:
  #
! #  { message word ... }
! # 
! # MESSAGE has the following values:
! #
! #   ""     file was loaded successfully
! #   "..."  file was not loaded successfully.
! #          A perror has been generated with MESSAGE.
! #
! # If the MESSAGE is "", then there is an optional set of words.
! # The words may be:
  #
+ #  nodebug  this file does not contain debug information
+ #
+ # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might
+ # be able to use this if they can get more information
+ # in the return value.
+ 
  proc gdb_file_cmd { arg } {
+     global gdb_prompt
      global verbose
      global GDB
  
      if [is_remote host] {
! 	set arg [remote_download host $arg]
  	if { $arg == "" } {
! 	    set message "download failed"
! 	    perror $message
! 	    return { $message }
  	}
      }
  
      send_gdb "file $arg\n"
      gdb_expect 120 {
+ 	-re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
+ 	    verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
+ 	    return { "" nodebug }
+ 	}
          -re "Reading symbols from.*done.*$gdb_prompt $" {
              verbose "\t\tLoaded $arg into the $GDB"
! 	    return { "" }
          }
          -re "A program is being debugged already.*Kill it.*y or n. $" {
              send_gdb "y\n"
*************** proc gdb_file_cmd { arg } {
*** 993,1024 ****
              gdb_expect 120 {
                  -re "Reading symbols from.*done.*$gdb_prompt $" {
                      verbose "\t\tLoaded $arg with new symbol table into $GDB"
!                     return 0
                  }
                  timeout {
!                     perror "(timeout) Couldn't load $arg, other program already loaded."
!                     return -1
                  }
              }
  	}
          -re "No such file or directory.*$gdb_prompt $" {
!             perror "($arg) No such file or directory\n"
!             return -1
          }
          -re "$gdb_prompt $" {
!             perror "couldn't load $arg into $GDB."
!             return -1
              }
          timeout {
!             perror "couldn't load $arg into $GDB (timed out)."
!             return -1
          }
          eof {
              # This is an attempt to detect a core dump, but seems not to
              # work.  Perhaps we need to match .* followed by eof, in which
              # gdb_expect does not seem to have a way to do that.
!             perror "couldn't load $arg into $GDB (end of file)."
!             return -1
          }
      }
  }
--- 1010,1046 ----
              gdb_expect 120 {
                  -re "Reading symbols from.*done.*$gdb_prompt $" {
                      verbose "\t\tLoaded $arg with new symbol table into $GDB"
! 		    return { "" }
                  }
                  timeout {
!                     set message "(timeout) Couldn't load $arg, other program already loaded."
! 		    perror $message
! 		    return { $message }
                  }
              }
  	}
          -re "No such file or directory.*$gdb_prompt $" {
!             set message "($arg) No such file or directory"
!             perror $message
! 	    return { $message }
          }
          -re "$gdb_prompt $" {
!             set message "couldn't load $arg into $GDB."
!             perror $message
! 	    return { $message }
              }
          timeout {
!             set message "couldn't load $arg into $GDB (timed out)."
! 	    perror $message
! 	    return { $message }
          }
          eof {
              # This is an attempt to detect a core dump, but seems not to
              # work.  Perhaps we need to match .* followed by eof, in which
              # gdb_expect does not seem to have a way to do that.
!             set message "couldn't load $arg into $GDB (end of file)."
! 	    perror $message
! 	    return { $message }
          }
      }
  }
*************** proc gdb_exit { } {
*** 1633,1639 ****
  
  #
  # gdb_load -- load a file into the debugger.
- #             return a -1 if anything goes wrong.
  #
  proc gdb_load { arg } {
      return [gdb_file_cmd $arg]
--- 1655,1660 ----
Index: gdb.base/remote.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/remote.exp,v
retrieving revision 1.3
diff -c -3 -p -r1.3 remote.exp
*** gdb.base/remote.exp	17 Jul 2001 21:47:19 -0000	1.3
--- gdb.base/remote.exp	27 Aug 2004 23:36:10 -0000
***************
*** 1,4 ****
! #   Copyright 1999, 2001 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
--- 1,4 ----
! # Copyright 1999, 2001, 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
*************** proc gdb_load_timed {executable download
*** 119,125 ****
      set load_begin_time [clock clicks]
      set result [gdb_load $executable]
      set load_end_time [clock clicks]
!     if {$result < 0} then { fail "$test - loading executable"; return }
      verbose "$test - time [expr ($load_end_time - $load_begin_time) / 1000] ms"
      pass $test
  }
--- 119,128 ----
      set load_begin_time [clock clicks]
      set result [gdb_load $executable]
      set load_end_time [clock clicks]
!     if { [lindex $result 0] != "" } then {
! 	fail "$test - loading executable"
! 	return
!     }
      verbose "$test - time [expr ($load_end_time - $load_begin_time) / 1000] ms"
      pass $test
  }
Index: gdb.gdb/complaints.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.gdb/complaints.exp,v
retrieving revision 1.2
diff -c -3 -p -r1.2 complaints.exp
*** gdb.gdb/complaints.exp	24 Sep 2002 16:07:42 -0000	1.2
--- gdb.gdb/complaints.exp	27 Aug 2004 23:36:10 -0000
***************
*** 1,5 ****
! #   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
--- 1,5 ----
! # Copyright 2002, 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
***************
*** 15,23 ****
  # 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 Andrew Cagney (cagney at redhat dot com),
  # derived from xfullpath.exp (written by Joel Brobecker), derived from
  # selftest.exp (written by Rob Savoye).
--- 15,20 ----
*************** proc setup_test { executable } {
*** 51,64 ****
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
!     if {[gdb_load $executable] <0} then {
! 	set timeout $oldtimeout
! 	verbose "Timeout is now $timeout seconds" 2
! 	return -1
!     }
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
      # Set a breakpoint at main
      gdb_test "break captured_command_loop" \
              "Breakpoint.*at.* file.*, line.*" \
--- 48,62 ----
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
! 
!     set result [gdb_load $executable]
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
+     if { [lindex $result 0] != "" } then {
+ 	return -1
+     }
+ 
      # Set a breakpoint at main
      gdb_test "break captured_command_loop" \
              "Breakpoint.*at.* file.*, line.*" \
Index: gdb.gdb/observer.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.gdb/observer.exp,v
retrieving revision 1.4
diff -c -3 -p -r1.4 observer.exp
*** gdb.gdb/observer.exp	13 Jul 2004 14:36:44 -0000	1.4
--- gdb.gdb/observer.exp	27 Aug 2004 23:36:10 -0000
*************** proc setup_test { executable } {
*** 46,59 ****
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
!     if {[gdb_load $executable] <0} then {
! 	set timeout $oldtimeout
! 	verbose "Timeout is now $timeout seconds" 2
! 	return -1
!     }
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
      # Set a breakpoint at main
      gdb_test "break captured_main" \
              "Breakpoint.*at.* file.*, line.*" \
--- 46,60 ----
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
! 
!     set result [gdb_load $executable]
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
+     if { [lindex $result 0] != "" } then {
+ 	return -1
+     }
+ 
      # Set a breakpoint at main
      gdb_test "break captured_main" \
              "Breakpoint.*at.* file.*, line.*" \
Index: gdb.gdb/selftest.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.gdb/selftest.exp,v
retrieving revision 1.3
diff -c -3 -p -r1.3 selftest.exp
*** gdb.gdb/selftest.exp	13 Aug 2004 10:43:20 -0000	1.3
--- gdb.gdb/selftest.exp	27 Aug 2004 23:36:10 -0000
***************
*** 15,23 ****
  # 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 Rob Savoye. (rob@cygnus.com)
  
  if $tracelevel then {
--- 15,20 ----
*************** proc test_with_self { executable } {
*** 243,256 ****
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
!     if {[gdb_load $executable] <0} then {
! 	set timeout $oldtimeout
! 	verbose "Timeout is now $timeout seconds" 2
! 	return -1
!     }
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
      # disassemble yourself
      gdb_test "x/10i main" \
  	    "x/10i.*main.*main.$decimal.*main.$decimal.*" \
--- 240,254 ----
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
! 
!     set result [gdb_load $executable]
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
+     if { [lindex $result 0] != "" } then {
+ 	return -1
+     }
+ 
      # disassemble yourself
      gdb_test "x/10i main" \
  	    "x/10i.*main.*main.$decimal.*main.$decimal.*" \
Index: gdb.gdb/xfullpath.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.gdb/xfullpath.exp,v
retrieving revision 1.2
diff -c -3 -p -r1.2 xfullpath.exp
*** gdb.gdb/xfullpath.exp	30 Aug 2003 04:58:21 -0000	1.2
--- gdb.gdb/xfullpath.exp	27 Aug 2004 23:36:10 -0000
***************
*** 1,5 ****
! #   Copyright 2002, 2003
! #   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
--- 1,5 ----
! # Copyright 2002, 2003, 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
***************
*** 15,23 ****
  # 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 Joel Brobecker. (brobecker@gnat.com), derived
  # from selftest.exp, written by Rob Savoye.
  
--- 15,20 ----
*************** proc setup_test { executable } {
*** 50,63 ****
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
!     if {[gdb_load $executable] <0} then {
! 	set timeout $oldtimeout
! 	verbose "Timeout is now $timeout seconds" 2
! 	return -1
!     }
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
      # Set a breakpoint at main
      gdb_test "break captured_main" \
              "Breakpoint.*at.* file.*, line.*" \
--- 47,61 ----
      set oldtimeout $timeout
      set timeout 600
      verbose "Timeout is now $timeout seconds" 2
! 
!     set result [gdb_load $executable]
      set timeout $oldtimeout
      verbose "Timeout is now $timeout seconds" 2
  
+     if { [lindex $result 0] != "" } then {
+ 	return -1
+     }
+ 
      # Set a breakpoint at main
      gdb_test "break captured_main" \
              "Breakpoint.*at.* file.*, line.*" \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]