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


Mumit,

We have a similar problem with Java, where the real "main" is the main 
method of the class that you told gcj was the main class of your
application.  There is a C main that gcj cooks up, and which Java
programmers definitely didn't want to know about...

The real solution is to have the compiler be able to emit some debug
information that would tell gdb what the user visible main is.  I am
kind of leery of starting to hard-code heuristics for all the various cases
of "real" mains that might crop up. 

However, given that we don't have a good "entry point" symbol right
now, it is okay to guess in gdbtk.  However, if we are going to do
this, then it would probably be better to abstract it a little bit,
and have a list of potential main's in order, and read it out of the
preferences file, rather than hard coding a set of choices.  So
something like putting:

pref define gdb/main_names  [list MAIN__ MAIN_ main]

in prefs.tcl

and then getting this list with "pref get", and doing a foreach in
your first srcwin.itb modification.  Also, it is probably better to do 

gdb_search functions -static 1 MAIN__

and then do gdb_loc on what you found.  This is faster, and more
straight-forward.

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...

What do you think?

Jim

 > When you start debugging a g77 generated program, you'll have the 
 > somewhat disconcerting experience of jumping into main, and stare
 > at what is typically a bunch of startup-style assembly code.
 > 
 > This trivial patch checks for MAIN__ and MAIN___ (depends on the target's
 > underscoring habits, but only MAIN__ may suffice) before main. Tested
 > on Linux and Cygwin. Could someone check on HPUX (no underscoring case)
 > to see what g77 emits there?
 > 
 > Against ss-1999-08-23.
 > 
 > Fri Aug 27 00:07:10 1999  Mumit Khan  <khan@xraylith.wisc.edu>
 > 
 > 	* srcwin.itb (SrcWin::_build_win): Check for g77 MAIN before
 > 	checking for main.
 > 	(SrcWin::location): Likewise.
 > 	(SrcWin::point_to_main): Likewise.
 > 	* interface.tcl (run_executable): Likewise.
 > 
 > --- srcwin.itb.~1	Thu Aug 26 23:48:34 1999
 > +++ srcwin.itb	Fri Aug 27 00:09:38 1999
 > @@ -144,7 +144,9 @@ body SrcWin::_build_win {} {
 >    if {$gdb_running} {
 >      update
 >    } else {
 > -    if {![catch {gdb_loc main} linespec]} {
 > +    if {![catch {gdb_loc MAIN__} linespec] \
 > +        || ![catch {gdb_loc MAIN___} linespec] \
 > +        || ![catch {gdb_loc main} linespec]} {
 >        location BROWSE_TAG $linespec
 >      }
 >    }
 > @@ -420,7 +422,9 @@ 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 {gdb_loc MAIN__} linespec] \
 > +          && [catch {gdb_loc MAIN___} linespec] \
 > +          && [catch {gdb_loc main} linespec]} {
 >  	# no "main" function found
 >  	return 
 >        }
 > @@ -765,7 +769,9 @@ 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 {gdb_loc MAIN__} loc] \
 > +      && [catch {gdb_loc MAIN___} loc] \
 > +      && [catch {gdb_loc main} loc]} {
 >      gdbtk_update
 >      debug "could not find main"
 >    } else {
 > --- interface.tcl.~1	Fri Aug 27 00:23:36 1999
 > +++ interface.tcl	Fri Aug 27 00:28:51 1999
 > @@ -964,8 +964,16 @@ 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 "clear MAIN___"}
 >        catch {gdb_cmd "clear main"}
 > -      catch {gdb_cmd "break main"}
 > +      # For fortran, we try MAIN__ and MAIN__ first.
 > +      if {![catch {gdb_loc MAIN__}] || ![catch {gdb_loc MAIN__}]} {
 > +	catch {gdb_cmd "break MAIN__"}
 > +	catch {gdb_cmd "break MAIN___"}
 > +      } else {
 > +	catch {gdb_cmd "break main"}
 > +      }
 >      }
 >  
 >      # set BP at user-specified function
 > 
 > Regards,
 > Mumit
 > 
 > 

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