This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


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

Patch: handle N_MAIN stab



The java programming language doesn't have the same notion of "main"
that C and C++ do.  Any class can have a static main method.

Gcj lets you specify which main you want at link time with the --main=
option.  The compiler driver generates a little C source with a proper
"main", which simply calls java runtime initialization code, and
invokes the user's main.  Unfortunately, this is a pain when
debugging....

[green@adsl-63-195-83-169 /tmp]$ ~/java/net/gdb/b/gdb/gdb h
GNU gdb 20000204
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) list
2     /tmp/ccv1saFNmain.i: No such file or directory.


/tmp/ccv1saFNmain.i was the temporary source file created by the
compiler driver with the C "main" in it.


What we really want is 

[green@adsl-63-195-83-169 /tmp]$ ~/java/net/gdb/b/gdb/gdb h
GNU gdb 20000204
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) list
1	public class h
2	{
3	public static void main (String[] args)
4	{
5	  int x = 5;
6	  boolean b1 = true;
7	  boolean b2 = false;
8	  System.out.println ("Hello");
9	}
10	}


Jim Blandy once pointed out that there's a stab for this: N_MAIN.

Gdb currently ignores N_MAIN.  The following patch is an attempt to
make it understand N_MAIN.  IIRC, Insight puts a break at main on
startup.  It will also need a patch.

I tested this change with a simple change to the gcj compiler driver
(jvgenmain actually), and it appears to work.

2000-03-05  Anthony Green  <green@redhat.com>

	* defs.h (main_name): Declare.
	* dbxread.c (process_one_symbol): Handle the N_MAIN stab by
	setting main_name.
	* blockframe.c (inside_main_func): Use main_name instead of
	"main".
	* symtab.c (find_main_psymtab): Ditto.
	* source.c (select_source_symtab): Ditto.
	* nlmread.c (nlm_symfile_read): Ditto.
	* rs6000-tdep.c (skip_prologue): Ditto.


Index: gdb//blockframe.c
===================================================================
RCS file: /cvs/src/src/gdb/blockframe.c,v
retrieving revision 1.1.1.11
diff -p -r1.1.1.11 blockframe.c
*** blockframe.c	1999/12/22 21:45:03	1.1.1.11
--- blockframe.c	2000/03/05 10:20:27
*************** inside_main_func (pc)
*** 127,133 ****
      {
        struct symbol *mainsym;
  
!       mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL);
        if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
  	{
  	  symfile_objfile->ei.main_func_lowpc =
--- 127,133 ----
      {
        struct symbol *mainsym;
  
!       mainsym = lookup_symbol (main_name, NULL, VAR_NAMESPACE, NULL, NULL);
        if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
  	{
  	  symfile_objfile->ei.main_func_lowpc =
Index: gdb//dbxread.c
===================================================================
RCS file: /cvs/src/src/gdb/dbxread.c,v
retrieving revision 1.1.1.10
diff -p -r1.1.1.10 dbxread.c
*** dbxread.c	2000/01/06 03:06:36	1.1.1.10
--- dbxread.c	2000/03/05 10:20:29
*************** process_one_symbol (type, desc, valu, na
*** 2426,2438 ****
  	}
        break;
  
        /* The following symbol types can be ignored.  */
      case N_OBJ:		/* Solaris 2:  Object file dir and name */
        /*   N_UNDF:                   Solaris 2:  file separator mark */
        /*   N_UNDF: -- we will never encounter it, since we only process one
           file's symbols at once.  */
      case N_ENDM:		/* Solaris 2:  End of module */
-     case N_MAIN:		/* Name of main routine.  */
      case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
        break;
      }
--- 2426,2442 ----
  	}
        break;
  
+     case N_MAIN:		/* Name of main routine.  */
+       if (name)
+ 	main_name = xstrdup (name);
+       break;
+ 
        /* The following symbol types can be ignored.  */
      case N_OBJ:		/* Solaris 2:  Object file dir and name */
        /*   N_UNDF:                   Solaris 2:  file separator mark */
        /*   N_UNDF: -- we will never encounter it, since we only process one
           file's symbols at once.  */
      case N_ENDM:		/* Solaris 2:  End of module */
      case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
        break;
      }
Index: gdb//defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.9
diff -p -r1.9 defs.h
*** defs.h	2000/03/04 02:23:06	1.9
--- defs.h	2000/03/05 10:20:30
*************** enum gdb_rc gdb_list_thread_ids (/* outp
*** 1314,1317 ****
--- 1314,1321 ----
  
  /* Switch thread and print notification. */
  #endif
+ 
+ /* From source.c  */
+ extern char *main_name;
+ 
  #endif /* #ifndef DEFS_H */
Index: gdb//nlmread.c
===================================================================
RCS file: /cvs/src/src/gdb/nlmread.c,v
retrieving revision 1.1.1.4
diff -p -r1.1.1.4 nlmread.c
*** nlmread.c	1999/08/09 21:33:43	1.1.1.4
--- nlmread.c	2000/03/05 10:20:31
*************** nlm_symfile_read (objfile, mainline)
*** 206,212 ****
    stabsect_build_psymtabs (objfile, mainline, ".stab",
  			   ".stabstr", ".text");
  
!   mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL);
  
    if (mainsym
        && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
--- 206,212 ----
    stabsect_build_psymtabs (objfile, mainline, ".stab",
  			   ".stabstr", ".text");
  
!   mainsym = lookup_symbol (main_name, NULL, VAR_NAMESPACE, NULL, NULL);
  
    if (mainsym
        && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
Index: gdb//rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.5
diff -p -r1.5 rs6000-tdep.c
*** rs6000-tdep.c	2000/02/26 09:30:30	1.5
--- rs6000-tdep.c	2000/03/05 10:20:32
*************** skip_prologue (CORE_ADDR pc, struct rs60
*** 573,579 ****
  	     function as well. */
  
  	  tmp = find_pc_misc_function (pc);
! 	  if (tmp >= 0 && STREQ (misc_function_vector[tmp].name, "main"))
  	    return pc + 8;
  	}
      }
--- 573,579 ----
  	     function as well. */
  
  	  tmp = find_pc_misc_function (pc);
! 	  if (tmp >= 0 && STREQ (misc_function_vector[tmp].name, main_name))
  	    return pc + 8;
  	}
      }
Index: gdb//source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.1.1.12
diff -p -r1.1.1.12 source.c
*** source.c	2000/02/03 04:14:35	1.1.1.12
--- source.c	2000/03/05 10:20:35
*************** static int first_line_listed;
*** 119,124 ****
--- 119,127 ----
  
  static struct symtab *last_source_visited = NULL;
  static int last_source_error = 0;
+ 
+ /* The default "main" symbol.  */
+ char *main_name = "main";
  
  
  /* Set the source file default for the "list" command to be S.
*************** select_source_symtab (s)
*** 151,159 ****
  
    /* Make the default place to list be the function `main'
       if one exists.  */
!   if (lookup_symbol ("main", 0, VAR_NAMESPACE, 0, NULL))
      {
!       sals = decode_line_spec ("main", 1);
        sal = sals.sals[0];
        free (sals.sals);
        current_source_symtab = sal.symtab;
--- 154,162 ----
  
    /* Make the default place to list be the function `main'
       if one exists.  */
!   if (lookup_symbol (main_name, 0, VAR_NAMESPACE, 0, NULL))
      {
!       sals = decode_line_spec (main_name, 1);
        sal = sals.sals[0];
        free (sals.sals);
        current_source_symtab = sal.symtab;
Index: gdb//symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.2
diff -p -r1.2 symtab.c
*** symtab.c	2000/02/08 04:39:02	1.2
--- symtab.c	2000/03/05 10:20:37
*************** find_main_psymtab ()
*** 1172,1178 ****
  
    ALL_PSYMTABS (objfile, pst)
    {
!     if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
        {
  	return (pst);
        }
--- 1172,1178 ----
  
    ALL_PSYMTABS (objfile, pst)
    {
!     if (lookup_partial_symbol (pst, main_name, 1, VAR_NAMESPACE))
        {
  	return (pst);
        }

-- 
Anthony Green                                                        Red Hat
                                                       Sunnyvale, California

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