GDB (API)
/home/stan/gdb/src/gdb/gdbtk/library/main.tcl
Go to the documentation of this file.
00001 # GDBtk (Insight) entry point
00002 # Copyright (C) 1997, 1998, 1999, 2002, 2003, 2004, 2008 Red Hat, Inc.
00003 #
00004 # This program is free software; you can redistribute it and/or modify it
00005 # under the terms of the GNU General Public License (GPL) as published by
00006 # the Free Software Foundation; either version 2 of the License, or (at
00007 # your option) any later version.
00008 #
00009 # This program is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 # GNU General Public License for more details.
00013 
00014 
00015 # State is controlled by 5 global boolean variables.
00016 #
00017 # gdb_target_changed
00018 # gdb_exe_changed
00019 # gdb_running
00020 # gdb_downloading
00021 # gdb_loaded
00022 
00023 ################### Initialization code #########################
00024 
00025 # If GDBtk fails to start at all, you might want to uncomment one or 
00026 # both of these.
00027 #set tcl_traceExec 2
00028 #set tcl_traceCompile 1
00029 
00030 # Add gdb's Tcl library directory to the end of the auto-load search path, if 
00031 # it isn't already on the path.
00032 # Also, add the plugins directory if it exists.
00033 # Note: GDBTK_LIBRARY will be set in tcl_findLibrary before main.tcl is called.
00034 
00035 set gdb_plugins ""
00036 if {[info exists auto_path]} {
00037   if {[lsearch -exact $auto_path $GDBTK_LIBRARY] < 0} {
00038     lappend auto_path $GDBTK_LIBRARY
00039   }
00040 
00041   # Add default plugins directory, which will be [name of exe]/../../lib/insight1.0
00042   set exename [info nameofexecutable]
00043   set dir [file join [file dirname [file dirname $exename]] lib insight1.0]
00044   if {[file exists $dir]} {
00045     lappend gdb_plugins $dir
00046     lappend auto_path $dir
00047   }
00048   # Add any user-specified plugins directories
00049   if {[info exists env(INSIGHT_PLUGINS)]} {
00050     set dirs [split $env(INSIGHT_PLUGINS) :]
00051     lappend gdb_plugins $dirs
00052     lappend auto_path $dirs
00053   }
00054 }
00055 
00056 # Require the packages we need.  Most are loaded already, but this will catch 
00057 # any odd errors... :
00058 
00059 foreach p {{Tcl 8.4} {Tk 8.4} {Itcl 3.3} {Itk 3.3} {Iwidgets 4.0} {Gdbtk 1.0} {combobox 2.2} {debug 1.0}} {
00060   if {[catch {package require [lindex $p 0] [lindex $p 1]} msg]} {
00061     if {![info exists ::env(GDBTK_TEST_RUNNING)] || $::env(GDBTK_TEST_RUNNING) == 0} {
00062       if {$::tcl_platform(platform) != "windows"} {
00063   puts stderr "Error: $msg"
00064       }
00065       catch {tk_messageBox -title Error -message $msg -icon error -type ok}
00066     }
00067     exit -1
00068   } else {
00069     #puts "Loaded [lindex $p 0] $msg"
00070   }
00071 }
00072 
00073 namespace import itcl::*
00074 namespace import debug::*
00075 
00076 # Environment variables controlling debugging:
00077 # GDBTK_TRACE
00078 # unset or 0      no tracing
00079 # 1               tracing initialized but not started
00080 # 2               tracing initialized and started
00081 #
00082 # GDBTK_DEBUGFILE - filename to write debugging messages and
00083 # trace information (if tracing is enabled).
00084 #
00085 if {[info exists env(GDBTK_TRACE)] && $env(GDBTK_TRACE) != 0} {
00086   # WARNING: the tracing code must not trace into itself or
00087   # infinite recursion will result. As currently configured
00088   # the tracing code will not trace basic tcl functions or anything defined
00089   # before debug::init.  For this reason we must source the DebugWin
00090   # code before debug::init is called.
00091   source [file join $GDBTK_LIBRARY debugwin.ith]
00092   source [file join $GDBTK_LIBRARY debugwin.itb]
00093 
00094   # Calling this installs our hooks for tracing and profiling.
00095   # This WILL slow things down.
00096   ::debug::init
00097 
00098   if {$env(GDBTK_TRACE) == 2} {
00099     ::debug::trace_start
00100   }
00101 }
00102 
00103 if {[info exists env(GDBTK_DEBUG)] && $env(GDBTK_DEBUG) != 0} {
00104   if {[info exists env(GDBTK_DEBUGFILE)]} {
00105     ::debug::logfile $env(GDBTK_DEBUGFILE)
00106   } else {
00107     ::debug::logfile "insight.log"
00108   }
00109 }
00110 
00111 # For testing
00112 set _test(interactive) 0
00113 
00114 # Set up platform globals. We replace Tcl's tcl_platform with
00115 # our own version which knows the difference between cygwin and
00116 # mingw.
00117 global gdbtk_platform
00118 set gdbtk_platform(platform) $tcl_platform(platform)
00119 switch $tcl_platform(platform) {
00120   windows {
00121     if {[llength [info commands ide_cygwin_path]] == 0} {
00122       set gdbtk_platform(os) "mingw"
00123     } else {
00124       set gdbtk_platform(os) "cygwin"
00125     }
00126   }
00127 
00128   default {
00129     set gdbtk_platform(os) $tcl_platform(os)
00130   }
00131 }
00132 set gdbtk_platform(osVersion) $tcl_platform(osVersion)
00133 
00134 # set traces on state variables
00135 trace variable gdb_running w do_state_hook
00136 trace variable gdb_downloading w do_state_hook
00137 trace variable gdb_loaded w do_state_hook
00138 define_hook state_hook
00139 
00140 # set up preferences
00141 pref init
00142 
00143 # let libgui tell us how to feel
00144 standard_look_and_feel
00145 
00146 # now let GDB set its default preferences
00147 pref_set_defaults
00148 
00149 # read in preferences
00150 pref_read
00151 
00152 init_disassembly_flavor
00153 
00154 # initialize state variables
00155 initialize_gdbtk
00156 
00157 # Arrange for session code to notice when file changes.
00158 add_hook file_changed_hook Session::notice_file_change
00159 
00160 ManagedWin::init
00161 
00162 # This stuff will help us play nice with WindowMaker's AppIcons.
00163 # Can't do the first bit yet, since we don't get this from gdb...
00164 # wm command . [concat $argv0 $argv] 
00165 wm group . . 
00166 
00167 # some initial commands to get gdb in the right mode
00168 gdb_cmd {set height 0}
00169 gdb_cmd {set width 0}
00170 
00171 if {[info exists env(GDBTK_TEST_RUNNING)] && $env(GDBTK_TEST_RUNNING)} {
00172   set gdb_target_name "exec"
00173 } else {
00174   # gdb_target_name is the name of the GDB target; that is, the argument
00175   # to the GDB target command.
00176   set gdb_target_name ""
00177   # By setting gdb_target_changed, we force a target dialog
00178   # to be displayed on the first "run"
00179   set gdb_target_changed 1
00180 }
00181 
00182 update
00183 
00184 # Uncomment the next line if you want a splash screen at startup...
00185 # ManagedWin::open About -transient -expire 5000
00186 
00187 # initialize IPC to enable multiple Insight's to communicate
00188 # with each other.
00189 set iipc 0
00190 if {[pref get gdb/ipc/enabled]} {
00191   set ::insight_ipc [Iipc \#auto]
00192 }
00193 
00194 gdbtk_idle
00195 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines