OSDN Git Service

* tclIndex: Rebuilt.
authortromey <tromey>
Thu, 7 Dec 2000 21:56:25 +0000 (21:56 +0000)
committertromey <tromey>
Thu, 7 Dec 2000 21:56:25 +0000 (21:56 +0000)
* interface.tcl (set_exe_name): Save session.
(gdbtk_quit_check): Save session.
* session.tcl: New file.
* srcbar.tcl (create_menu_items): Add menu items to recall old
sessions.

gdb/gdbtk/library/ChangeLog
gdb/gdbtk/library/interface.tcl
gdb/gdbtk/library/session.tcl [new file with mode: 0644]
gdb/gdbtk/library/srcbar.tcl
gdb/gdbtk/library/srctextwin.itb
gdb/gdbtk/library/tclIndex

index e0ee7af..7c0a890 100644 (file)
@@ -1,5 +1,12 @@
 2000-12-07  Tom Tromey  <tromey@redhat.com>
 
+       * tclIndex: Rebuilt.
+       * interface.tcl (set_exe_name): Save session.
+       (gdbtk_quit_check): Save session.
+       * session.tcl: New file.
+       * srcbar.tcl (create_menu_items): Add menu items to recall old
+       sessions.
+
        * bpwin.itb (BpWin::goto_bp): Handle multiple source windows.
        * srctextwin.itb (SrcTextWin::get_file): New method.
        (SrcTextWin::set_tag_to_stack): New method.
index 675243a..a322d5b 100644 (file)
@@ -222,6 +222,8 @@ proc gdbtk_quit_check {} {
     if {![gdbtk_tcl_query $msg no]} {
       return 0
     }
+  } elseif {$gdb_exe_name != ""} {
+    session_save
   }
   return 1
 }
@@ -737,6 +739,10 @@ proc set_exe_name {exe} {
   global gdb_exe_name gdb_exe_changed
   #debug "set_exe_name: exe=$exe  gdb_exe_name=$gdb_exe_name"
 
+  if {$gdb_exe_name != ""} then {
+    session_save
+  }
+
   set gdb_exe_name $exe
   set gdb_exe_changed 1    
 }
diff --git a/gdb/gdbtk/library/session.tcl b/gdb/gdbtk/library/session.tcl
new file mode 100644 (file)
index 0000000..63288d7
--- /dev/null
@@ -0,0 +1,122 @@
+# Local preferences functions for GDBtk.
+# Copyright 2000 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) 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.
+
+#
+# This procedure decides what makes up a gdb `session'.  Roughly a
+# session is whatever the user found useful when debugging a certain
+# executable.
+#
+# Eventually we should expand this procedure to know how to save
+# window placement and contents.  That requires more work.
+#
+proc session_save {} {
+  global gdb_exe_name gdb_target_name
+  global gdb_current_directory gdb_source_path gdb_inferior_args
+
+  # gdb sessions are named after the executable.
+  set 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
+
+  # Some simple state the user wants.
+  set values(args) $gdb_inferior_args
+  set values(dirs) $gdb_source_path
+  set values(pwd) $gdb_current_directory
+  set values(target) $gdb_target_name
+
+  # Recompute list of recent sessions.  Trim to no more than 5 sessions.
+  set recent [concat [list $name] \
+               [lremove [pref getd gdb/recent-projects] $name]]
+  if {[llength $recent] > 5} then {
+    set recent [lreplace $recent 5 end]
+  }
+  pref setd gdb/recent-projects $recent
+
+  foreach k [array names values] {
+    pref setd $key/$k $values($k)
+  }
+  pref setd $key/all-keys [array names values]
+}
+
+#
+# Load a session saved with session_save.  NAME is the pretty name of
+# the session, as returned by session_list.
+#
+proc session_load {name} {
+  # gdb sessions are named after the executable.
+  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(dirs)]} {
+    # FIXME: short-circuit confirmation.
+    gdb_cmd "directory"
+    gdb_cmd "directory $values(dirs)"
+  }
+
+  if {[info exists values(pwd)]} {
+    gdb_cmd "cd $values(pwd)"
+  }
+
+  if {[info exists values(args)]} {
+    gdb_cmd "set args $values(args)"
+  }
+
+  if {[info exists values(executable)]} {
+    gdb_clear_file
+    set_exe_name $values(executable)
+    set_exe
+  }
+
+  # FIXME: handle target
+}
+
+#
+# Delete a session.  NAME is the internal name of the session.
+#
+proc session_delete {name} {
+  # FIXME: we can't yet fully define this because the libgui
+  # preference code doesn't supply a delete method.
+  set recent [lremove [pref getd gdb/recent-projects] $name]
+  pref setd gdb/recent-projects $recent
+}
+
+#
+# Return a list of all known sessions.  This returns the `pretty name'
+# of the session -- something suitable for a menu.
+#
+proc session_list {} {
+  set newlist {}
+  set result {}
+  foreach name [pref getd gdb/recent-projects] {
+    set exe [pref getd gdb/session/$name/executable]
+    # Take this opportunity to prune the list.
+    if {[file exists $exe]} then {
+      lappend newlist $name
+      lappend result $exe
+    } else {
+      # FIXME: if we could delete keys we would delete all keys
+      # associated with NAME now.
+    }
+  }
+  pref setd gdb/recent-projects $newlist
+  return $result
+}
index bfd1dcd..8249a5f 100644 (file)
@@ -123,6 +123,17 @@ class GDBSrcBar {
     add_menu_command Other "Source..." \
       "source_file" -underline 0
 
+    set sessions [session_list]
+    if {[llength $sessions]} {
+      add_menu_separator
+      set i 1
+      foreach item $sessions {
+       add_menu_command Other "$i $item" \
+         [list session_load $item] \
+         -underline 0
+      }
+    }
+
     add_menu_separator
 
     if {$tcl_platform(platform) == "windows"} {
@@ -136,21 +147,19 @@ class GDBSrcBar {
        "$this _apply_source print" \
        -underline 0 -accelerator "Ctrl+P"
       add_menu_separator
-
     }
-    
+
     add_menu_command Other "Target Settings..." "set_target_name" \
       -underline 0
     add_menu_separator
     add_menu_command None "Exit" gdbtk_quit -underline 1
-    
+
     create_run_menu
 
     create_view_menu
 
     if {[pref get gdb/control_target]} {
       create_control_menu
-
     }
 
     if {[pref get gdb/mode]} {
index 9fde1a4..44961af 100644 (file)
@@ -2096,7 +2096,7 @@ body SrcTextWin::do_source_popup { X Y x y } {
     $popups(source) add command -label "Open Source in external editor" \
       -command [list $parent edit]
   }
-  
+
   tk_popup $popups(source) $X $Y 
 }
 
index 08a3876..b6d7a70 100644 (file)
@@ -82,6 +82,10 @@ set auto_index(escape_value) [list source [file join $dir prefs.tcl]]
 set auto_index(unescape_value) [list source [file join $dir prefs.tcl]]
 set auto_index(pref_set_defaults) [list source [file join $dir prefs.tcl]]
 set auto_index(pref_src-font_trace) [list source [file join $dir prefs.tcl]]
+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(GDBSrcBar) [list source [file join $dir srcbar.tcl]]
 set auto_index(TdumpWin) [list source [file join $dir tdump.tcl]]
 set auto_index(TfindArgs) [list source [file join $dir tfind_args.tcl]]