OSDN Git Service

* tclIndex: Updated.
authortromey <tromey>
Sun, 28 Oct 2001 20:08:38 +0000 (20:08 +0000)
committertromey <tromey>
Sun, 28 Oct 2001 20:08:38 +0000 (20:08 +0000)
* library/main.tcl: Add session_notice_file_change to
file_changed_hook.
* library/session.tcl (session_load): Only load the executable.
(session_notice_file_change): New proc.
(SESSION_exe_name): New proc.
(session_save): Use it.
(session_notice_file_change): Likewise.
* library/interface.tcl (gdbtk_tcl_exec_file_display): Don't call
session_save.
(gdbtk_tcl_preloop): Don't set executable name or try to find
main.  Notice a new session if required.

gdb/gdbtk/ChangeLog
gdb/gdbtk/library/interface.tcl
gdb/gdbtk/library/main.tcl
gdb/gdbtk/library/session.tcl
gdb/gdbtk/library/tclIndex

index d4992dc..79455d1 100644 (file)
@@ -1,3 +1,18 @@
+2001-10-27  Tom Tromey  <tromey@redhat.com>
+
+       * tclIndex: Updated.
+       * library/main.tcl: Add session_notice_file_change to
+       file_changed_hook.
+       * library/session.tcl (session_load): Only load the executable.
+       (session_notice_file_change): New proc.
+       (SESSION_exe_name): New proc.
+       (session_save): Use it.
+       (session_notice_file_change): Likewise.
+       * library/interface.tcl (gdbtk_tcl_exec_file_display): Don't call
+       session_save.
+       (gdbtk_tcl_preloop): Don't set executable name or try to find
+       main.  Notice a new session if required.
+
 2001-10-18  Martin M. Hunt  <hunt@redhat.com>
 
        * library/srcpref.itb (SrcPref::contructor): Move array
index 7dea405..a95643a 100644 (file)
@@ -111,14 +111,11 @@ proc gdbtk_tcl_preloop { } {
   after idle gdbtk_idle 
   ManagedWin::startup
 
-  SrcWin::point_to_main
-  set msg ""
-  catch {gdb_cmd "info files"} msg
-  set line1 [string range $msg 0 [string first \n $msg]]  
-  if {[regexp {Symbols from "(.*)"\.} $line1 dummy name]} {
-    set gdb_exe_name $name
+  if {$gdb_exe_name != ""} {
+    # At startup, file_changed_hook is called too late for us, so we
+    # must notice the initial session by hand.
+    session_notice_file_change
   }
-
   
   gdbtk_update
 }
@@ -772,9 +769,6 @@ proc gdbtk_tcl_exec_file_display {filename} {
   set_exe_name $filename
   set gdb_exe_changed 0
 
-  # Add this new session to the session list
-  session_save
-
   SrcWin::point_to_main
 }
 
index 90edbfc..aaa28d9 100644 (file)
@@ -137,6 +137,9 @@ pref_read
 
 init_disassembly_flavor
 
+# Arrange for session code to notice when file changes.
+add_hook file_changed_hook session_notice_file_change
+
 ManagedWin::init
 
 # This stuff will help us play nice with WindowMaker's AppIcons.
index d7a2bbe..9107114 100644 (file)
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
+# An internal function for canonicalizing path names.  This probably
+# should use `realpath', but that is more work.  So for now we neglect
+# the possibility of symlinks.
+proc SESSION_exe_name {path} {
+  global tcl_platform
+
+  # Get real directory.
+  if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    set path [ide_cygwin_path to_win32 $path]
+  }
+  set save [pwd]
+  cd [file dirname $path]
+  set dir [pwd]
+  cd $save
+  return [file join $dir [file tail $path]]
+}
+
 # An internal function used when saving sessions.  Returns a string
 # that can be used to recreate all pertinent breakpoint state.
 proc SESSION_serialize_bps {} {
@@ -110,14 +127,15 @@ proc session_save {} {
   global gdb_current_directory gdb_source_path
 
   # gdb sessions are named after the executable.
-  set name $gdb_exe_name
+  set name [SESSION_exe_name $gdb_exe_name]
   set key gdb/session/$name
 
   # We fill a hash and then use that to set the actual preferences.
 
   # Always set the exe. name in case we later decide to change the
-  # interpretation of the session key.
-  set values(executable) $gdb_exe_name
+  # interpretation of the session key.  Use the full path to the
+  # executable.
+  set values(executable) $name
 
   # Some simple state the user wants.
   set values(args) [gdb_get_inferior_args]
@@ -157,6 +175,39 @@ proc session_load {name} {
     set values($k) [pref getd $key/$k]
   }
 
+  if {[info exists values(executable)]} {
+    gdb_clear_file
+    set_exe_name $values(executable)
+    set_exe
+  }
+}
+
+#
+# This is called from file_changed_hook.  It does all the work of
+# loading a session, if one exists with the same name as the current
+# executable.
+#
+proc session_notice_file_change {} {
+  global gdb_exe_name gdb_target_name
+
+  debug "noticed file change event for $gdb_exe_name"
+
+  # gdb sessions are named after the executable.
+  set name [SESSION_exe_name $gdb_exe_name]
+  set key gdb/session/$name
+
+  # Fetch all keys for this session into an array.
+  foreach k [pref getd $key/all-keys] {
+    set values($k) [pref getd $key/$k]
+  }
+
+  if {! [info exists values(executable)] || $values(executable) != $name} {
+    # No such session.
+    return
+  }
+
+  debug "reloading session for $gdb_exe_name"
+
   if {[info exists values(dirs)]} {
     # FIXME: short-circuit confirmation.
     gdb_cmd "directory"
@@ -171,12 +222,6 @@ proc session_load {name} {
     gdb_set_inferior_args $values(args)
   }
 
-  if {[info exists values(executable)]} {
-    gdb_clear_file
-    set_exe_name $values(executable)
-    set_exe
-  }
-
   if {[info exists values(breakpoints)]} {
     SESSION_recreate_bps $values(breakpoints)
   }
index df7a350..060865f 100644 (file)
@@ -94,6 +94,7 @@ set auto_index(session_save) [list source [file join $dir session.tcl]]
 set auto_index(session_load) [list source [file join $dir session.tcl]]
 set auto_index(session_delete) [list source [file join $dir session.tcl]]
 set auto_index(session_list) [list source [file join $dir session.tcl]]
+set auto_index(session_notice_file_change) [list source [file join $dir session.tcl]]
 set auto_index(TdumpWin) [list source [file join $dir tdump.tcl]]
 set auto_index(TfindArgs) [list source [file join $dir tfind_args.tcl]]
 set auto_index(oldGDBToolBar) [list source [file join $dir toolbar.tcl]]