This is the mail archive of the insight@sourceware.cygnus.com mailing list for the Insight project.


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

Re: (patch) g77 helper


James Ingham <jingham@cygnus.com> writes:
> 
> Using the preferences will make it clearer, and more adaptable, and if
> someone has some bizarre case, they can go edit the prefs file and add
> their case.  We could even stick this in the preferences dialog
> somewhere.
> 
> You should also remember what main you found, probably in a global
> variable, though it might be good to put a little wrapper fn. in
> interface.tcl to get and set it.  That is better than again just
> blindly setting and unsetting the list...
> 

Jim, Thanks for the feedback. How about the following patch? 

I'm not setting a global since I haven't looked at the code enough to 
see what needs to be reinitialized when a new file is loaded etc. In 
theory, caching the name of the main and then re-using it should speed
up parts of the code, but I need to study the code a bit to see where
it needs to be reset correctly. Since this change isn't that much
slower than the existing code, I'll punt on this until I get some free
time. There are only so many weekends in a week ;-)

Mon Aug 30 15:21:02 1999  Mumit Khan  <khan@xraylith.wisc.edu>

	* prefs.tcl (pref_set_defaults): Add main_names preference.
	* interface.tcl (gdbtk_locate_main): New proc.
	(run_executable): Use.
	* srcwin.itb (SrcWin::_build_win): Use.
	(SrcWin::location): Likewise.
	(SrcWin::point_to_main): Likewise.


--- prefs.tcl.~1	Mon Aug 30 14:50:23 1999
+++ prefs.tcl	Mon Aug 30 14:52:13 1999
@@ -322,6 +322,9 @@ proc pref_set_defaults {} {
 
   # Kernel Objects (kod)
   pref define gdb/kod/show_icon           0
+
+  # Various possible "main" functions. What's for Java?
+  pref define gdb/main_names              [list MAIN___ MAIN__ main]
 }
 
 # This traces the global/fixed font and forces src-font to
--- interface.tcl.~1	Mon Aug 30 15:26:33 1999
+++ interface.tcl	Mon Aug 30 15:40:08 1999
@@ -647,6 +647,35 @@ proc gdbtk_tcl_exec_file_display {filena
   SrcWin::point_to_main
 }
 
+# ------------------------------------------------------------------
+#  PROCEDURE: gdbtk_locate_main 
+#         This proc tries to locate a suitable main function from
+#         a list of names defined in the gdb/main_names preference; 
+#         returns the linespec (see below) if found, or raises error.
+#
+#  The return linespec looks like this:
+#  0: basename of the file
+#  1: function name
+#  2: full filename
+#  3: source line number
+#  4: address
+#  5: current PC - which will often be the same as address, but not when
+#  6: shared library name if the pc is in a shared lib
+#  we are browsing, or walking the stack.
+#
+# ------------------------------------------------------------------
+proc gdbtk_locate_main {} {
+  set main_names [pref get gdb/main_names]
+  debug "gdbtk_locate_main: Searching $main_names"
+  foreach main $main_names {
+    if {![catch {gdb_search functions $main -static 1}] \
+        && ![catch {gdb_loc $main} linespec]} {
+      return $linespec
+    }
+  }
+  error "cannot locate a suitable main"
+}
+
 ##############################################
 #  The rest of this file is an assortment of Tcl wrappers
 #  for various bits of gdb functionality.
@@ -968,9 +997,13 @@ proc run_executable { {auto_start 1} } {
     }
       
     if {[pref get gdb/load/main]} {
-      debug "Setting new BP at main"
-      catch {gdb_cmd "clear main"}
-      catch {gdb_cmd "break main"}
+      set main "main"
+      if {![catch {gdbtk_locate_main} linespec]} {
+        set main [lindex $linespec 1]
+      }
+      debug "Setting new BP at $main"
+      catch {gdb_cmd "clear $main"}
+      catch {gdb_cmd "break $main"}
     }
 
     # set BP at user-specified function
@@ -1420,3 +1453,4 @@ proc initialize_gdbtk {} {
   # to be displayed on the first "run"
   set gdb_target_changed 1
 }
+
--- srcwin.itb.~1	Mon Aug 30 14:52:49 1999
+++ srcwin.itb	Mon Aug 30 15:32:10 1999
@@ -144,7 +144,7 @@ body SrcWin::_build_win {} {
   if {$gdb_running} {
     update
   } else {
-    if {![catch {gdb_loc main} linespec]} {
+    if {![catch {gdbtk_locate_main} linespec]} {
       location BROWSE_TAG $linespec
     }
   }
@@ -420,7 +420,7 @@ body SrcWin::location {tag linespec} {
     set tag BROWSE_TAG
     debug "not running: name=$name funcname=$funcname line=$line"
     if {$name == ""} {
-      if {[catch {gdb_loc main} linespec]} {
+      if {[catch {gdbtk_locate_main} linespec]} {
 	# no "main" function found
 	return 
       }
@@ -765,7 +765,7 @@ body SrcWin::point_to_main {} {
   # We need to force this to some default location. Assume main and
   # if that fails, let the source window guess (via gdb_loc using stop_pc).
   set src [lindex [ManagedWin::find SrcWin] 0]
-  if {[catch {gdb_loc main} loc]} {
+  if {[catch {gdbtk_locate_main} loc]} {
     gdbtk_update
     debug "could not find main"
   } else {

Regards,
Mumit


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