[rfa/sym*] Look at N_MAIN

Andrew Cagney ac131313@cygnus.com
Fri Mar 16 07:41:00 GMT 2001


(resolving this is part of the 5.1 release criteria)

The attatched patch gets GDB to make use of N_MAIN when available.  The
original, submitted by Anthony Green, needed some improvements (see
attatched e-mails).

I've addressed just the memory leak problem.

	Andrew
2001-03-16  Andrew Cagney  <ac131313@redhat.com>

	* symtab.c (main_name): New function.
	(set_main_name): New function.
	* symtab.h: Declare.

	From 2000-03-05 Anthony Green <green@redhat.com>:
	* 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: blockframe.c
===================================================================
RCS file: /cvs/src/src/gdb/blockframe.c,v
retrieving revision 1.13
diff -p -r1.13 blockframe.c
*** blockframe.c	2001/03/06 08:21:05	1.13
--- blockframe.c	2001/03/16 15:35:39
*************** inside_main_func (CORE_ADDR pc)
*** 120,126 ****
      {
        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 =
--- 120,126 ----
      {
        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: dbxread.c
===================================================================
RCS file: /cvs/src/src/gdb/dbxread.c,v
retrieving revision 1.15
diff -p -r1.15 dbxread.c
*** dbxread.c	2001/03/07 02:57:08	1.15
--- dbxread.c	2001/03/16 15:35:40
*************** process_one_symbol (int type, int desc, 
*** 2389,2401 ****
  	}
        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;
      }
--- 2389,2405 ----
  	}
        break;
  
+     case N_MAIN:		/* Name of main routine.  */
+       if (name)
+ 	set_main_name (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: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.43
diff -p -r1.43 defs.h
*** defs.h	2001/03/14 16:42:29	1.43
--- defs.h	2001/03/16 15:35:40
*************** enum gdb_rc gdb_list_thread_ids (/* outp
*** 1300,1303 ****
--- 1300,1304 ----
  
  /* Switch thread and print notification. */
  #endif
+ 
  #endif /* #ifndef DEFS_H */
Index: nlmread.c
===================================================================
RCS file: /cvs/src/src/gdb/nlmread.c,v
retrieving revision 1.7
diff -p -r1.7 nlmread.c
*** nlmread.c	2001/03/07 02:57:08	1.7
--- nlmread.c	2001/03/16 15:35:40
*************** nlm_symfile_read (struct objfile *objfil
*** 193,199 ****
    stabsect_build_psymtabs (objfile, mainline, ".stab",
  			   ".stabstr", ".text");
  
!   mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL);
  
    if (mainsym
        && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
--- 193,199 ----
    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: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.20
diff -p -r1.20 rs6000-tdep.c
*** rs6000-tdep.c	2001/03/06 08:21:16	1.20
--- rs6000-tdep.c	2001/03/16 15:35:41
*************** skip_prologue (CORE_ADDR pc, CORE_ADDR l
*** 752,758 ****
  	     function as well. */
  
  	  tmp = find_pc_misc_function (pc);
! 	  if (tmp >= 0 && STREQ (misc_function_vector[tmp].name, "main"))
  	    return pc + 8;
  	}
      }
--- 752,758 ----
  	     function as well. */
  
  	  tmp = find_pc_misc_function (pc);
! 	  if (tmp >= 0 && STREQ (misc_function_vector[tmp].name, main_name ()))
  	    return pc + 8;
  	}
      }
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.10
diff -p -r1.10 source.c
*** source.c	2001/03/06 08:21:17	1.10
--- source.c	2001/03/16 15:35:41
*************** select_source_symtab (register struct sy
*** 153,161 ****
  
    /* 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];
        xfree (sals.sals);
        current_source_symtab = sal.symtab;
--- 153,161 ----
  
    /* 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];
        xfree (sals.sals);
        current_source_symtab = sal.symtab;
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.32
diff -p -r1.32 symtab.c
*** symtab.c	2001/03/06 08:21:17	1.32
--- symtab.c	2001/03/16 15:35:42
*************** find_main_psymtab (void)
*** 1174,1180 ****
  
    ALL_PSYMTABS (objfile, pst)
    {
!     if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
        {
  	return (pst);
        }
--- 1174,1180 ----
  
    ALL_PSYMTABS (objfile, pst)
    {
!     if (lookup_partial_symbol (pst, main_name (), 1, VAR_NAMESPACE))
        {
  	return (pst);
        }
*************** decode_line_spec (char *string, int funf
*** 3351,3356 ****
--- 3351,3383 ----
      error ("Junk at end of line specification: %s", string);
    return sals;
  }
+ 
+ /* Track MAIN */
+ static char *name_of_main;
+ 
+ void
+ set_main_name (const char *name)
+ {
+   if (name_of_main != NULL)
+     {
+       xfree (name_of_main);
+       name_of_main = NULL;
+     }
+   if (name != NULL)
+     {
+       name_of_main = xstrdup (name);
+     }
+ }
+ 
+ char *
+ main_name (void)
+ {
+   if (name_of_main != NULL)
+     return name_of_main;
+   else
+     return "main";
+ }
+ 
  
  void
  _initialize_symtab (void)
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.20
diff -p -r1.20 symtab.h
*** symtab.h	2001/03/07 02:57:08	1.20
--- symtab.h	2001/03/16 15:35:59
*************** extern void search_symbols (char *, name
*** 1447,1450 ****
--- 1447,1457 ----
  extern void free_search_symbols (struct symbol_search *);
  extern struct cleanup *make_cleanup_free_search_symbols (struct symbol_search *);
  
+ /* The name of the ``main'' function.
+    FIXME: cagney/2001-03-20: Can't make main_name() const since some
+    of the calling code currently assumes that the string isn't
+    const. */
+ extern void set_main_name (const char *name);
+ extern /*const*/ char *main_name (void);
+ 
  #endif /* !defined(SYMTAB_H) */


More information about the Gdb-patches mailing list