This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [rfa/sym*] Look at N_MAIN
- To: Andrew Cagney <ac131313 at cygnus dot com>
- Subject: Re: [rfa/sym*] Look at N_MAIN
- From: Elena Zannoni <ezannoni at cygnus dot com>
- Date: Sun, 1 Apr 2001 20:06:08 -0400 (EDT)
- Cc: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- References: <3AB23416.EF23DDB2@cygnus.com>
Andrew Cagney writes:
> (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.
>
Looks OK to me. As long as we insert Jim K. comments about multiple
N_MAINs into a FIXME in dbxread.c.
Elena
> Andrew2001-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) */
> Return-Path: <gdb-patches-owner@sourceware.cygnus.com>
> Received: (from uucp@localhost)
> by andrew1.lnk.telstra.net (8.9.3/8.9.3) id VAA79744
> for <ac131313@localhost>; Sun, 5 Mar 2000 21:44:35 +1100 (EST)
> (envelope-from gdb-patches-owner@sourceware.cygnus.com)
> Received: from localhost.cygnus.com(127.0.0.1), claiming to be "b1.cygnus.com"
> via SMTP by localhost.cygnus.com, id smtpdX79742; Sun Mar 5 21:44:26 2000
> Received: from runyon.cygnus.com
> by b1.cygnus.com (fetchmail-4.5.4 POP3)
> for <ac131313/localhost> (multi-drop); Sun, 05 Mar 2000 21:44:26 EST
> Received: from sourceware.cygnus.com (sourceware.cygnus.com [205.180.83.71])
> by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with SMTP id CAA22592
> for <ac131313@cygnus.com>; Sun, 5 Mar 2000 02:39:47 -0800 (PST)
> Received: (qmail 13571 invoked by alias); 5 Mar 2000 10:39:40 -0000
> Received: (qmail 13545 invoked from network); 5 Mar 2000 10:39:37 -0000
> Received: from runyon.cygnus.com (HELO cygnus.com) (205.180.230.5)
> by sourceware.cygnus.com with SMTP; 5 Mar 2000 10:39:37 -0000
> Received: from hoser.cygnus.com (hoser.cygnus.com [205.180.230.193])
> by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id CAA22571;
> Sun, 5 Mar 2000 02:39:36 -0800 (PST)
> Received: (green@localhost) by hoser.cygnus.com (8.9.3/8.6.4) id CAA04980; Sun, 5 Mar 2000 02:39:35 -0800
> Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm
> Precedence: bulk
> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-ac131313=cygnus.com@sourceware.cygnus.com>
> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.cygnus.com>
> List-Archive: <http://sourceware.cygnus.com/ml/gdb-patches/>
> List-Post: <mailto:gdb-patches@sourceware.cygnus.com>
> List-Help: <mailto:gdb-patches-help@sourceware.cygnus.com>, <http://sourceware.cygnus.com/ml/#faqs>
> Sender: gdb-patches-owner@sourceware.cygnus.com
> Delivered-To: mailing list gdb-patches@sourceware.cygnus.com
> Date: Sun, 5 Mar 2000 02:39:35 -0800
> Message-Id: <200003051039.CAA04980@hoser.cygnus.com>
> X-Authentication-Warning: hoser.cygnus.com: green set sender to green@cygnus.com using -f
> From: Anthony Green <green@cygnus.com>
> To: gdb-patches@sourceware.cygnus.com
> CC: jimb@cygnus.com, tromey@cygnus.com
> Subject: Patch: handle N_MAIN stab
> X-Organization: Red Hat, Sunnyvale, California
> X-URL: http://www.cygnus.com/~green
> Reply-to: green@redhat.com
> Content-Type: text
> X-Mozilla-Status2: 00000000
>
>
> 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
>
>
> Return-Path: <gdb-patches-owner@sourceware.cygnus.com>
> Received: (from uucp@localhost)
> by andrew1.lnk.telstra.net (8.9.3/8.9.3) id AAA02531
> for <ac131313@localhost>; Thu, 9 Mar 2000 00:45:41 +1100 (EST)
> (envelope-from gdb-patches-owner@sourceware.cygnus.com)
> Received: from localhost.cygnus.com(127.0.0.1), claiming to be "b1.cygnus.com"
> via SMTP by localhost.cygnus.com, id smtpdve2380; Thu Mar 9 00:45:34 2000
> Received: from runyon.cygnus.com
> by b1.cygnus.com (fetchmail-4.5.4 POP3)
> for <ac131313/localhost> (multi-drop); Thu, 09 Mar 2000 00:45:34 EST
> Received: from sourceware.cygnus.com (sourceware.cygnus.com [205.180.83.71])
> by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with SMTP id IAA08250
> for <ac131313@cygnus.com>; Mon, 6 Mar 2000 08:36:53 -0800 (PST)
> Received: (qmail 2508 invoked by alias); 6 Mar 2000 16:36:51 -0000
> Received: (qmail 2464 invoked from network); 6 Mar 2000 16:36:46 -0000
> Received: from runyon.cygnus.com (HELO cygnus.com) (205.180.230.5)
> by sourceware.cygnus.com with SMTP; 6 Mar 2000 16:36:46 -0000
> Received: from rtl.cygnus.com (rtl.cygnus.com [205.180.230.21])
> by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id IAA08227;
> Mon, 6 Mar 2000 08:36:45 -0800 (PST)
> Received: (kingdon@localhost) by rtl.cygnus.com (8.6.12/8.6.4) id IAA19812; Mon, 6 Mar 2000 08:36:45 -0800
> Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm
> Precedence: bulk
> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-ac131313=cygnus.com@sourceware.cygnus.com>
> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.cygnus.com>
> List-Archive: <http://sourceware.cygnus.com/ml/gdb-patches/>
> List-Post: <mailto:gdb-patches@sourceware.cygnus.com>
> List-Help: <mailto:gdb-patches-help@sourceware.cygnus.com>, <http://sourceware.cygnus.com/ml/#faqs>
> Sender: gdb-patches-owner@sourceware.cygnus.com
> Delivered-To: mailing list gdb-patches@sourceware.cygnus.com
> To: green@redhat.com
> CC: gdb-patches@sourceware.cygnus.com
> CC: jimb@cygnus.com, tromey@cygnus.com
> Subject: Re: Patch: handle N_MAIN stab
> References: <200003051039.CAA04980@hoser.cygnus.com>
> From: Jim Kingdon <kingdon@redhat.com>
> Date: 06 Mar 2000 08:36:44 -0800
> In-Reply-To: Anthony Green's message of Sun, 5 Mar 2000 02:39:35 -0800
> Message-ID: <bsny4jbs3.fsf@rtl.cygnus.com>
> X-Mailer: Gnus v5.3/Emacs 19.34
> Content-Type: text
> X-Mozilla-Status2: 00000000
>
> > Gdb currently ignores N_MAIN. The following patch is an attempt to
> > make it understand N_MAIN.
>
> I looked over that patch and the basic concept looks fine. N_MAIN is
> already documented in doc/stabs.texinfo.
>
> The patch does leak memory every time symbols are reloaded, though (a
> bad thing in and of itself and also a hassle is using memory leak
> detecting programs). And probably has subtler bugs if one has a
> symbol file with N_MAIN and then replaces it with a symbol file with
> "main" and without N_MAIN. I'm not sure exactly what rule to follow
> but probably something like:
>
> * N_MAIN takes precedence over "main" no matter what objfile it is in
>
> * If there is more than one N_MAIN, choose the one in the
> symfile_objfile
>
> * If there is more than one N_MAIN within a given objfile, complain()
> and choose arbitrarily.
>
> I have no particularly strong objection if the maintainer (JimB, looks
> like) wants to relegate the above to FIXME comments or something, but
> I guess if you want my advice, it should be fairly easy to fix at
> least the memory leak now.
>
>
> Return-Path: <gdb-patches-owner@sourceware.cygnus.com>
> Received: (from uucp@localhost)
> by andrew1.lnk.telstra.net (8.9.3/8.9.3) id SAA71199
> for <ac131313@localhost>; Mon, 27 Mar 2000 18:40:47 +1000 (EST)
> (envelope-from gdb-patches-owner@sourceware.cygnus.com)
> Received: from localhost.cygnus.com(127.0.0.1), claiming to be "b1.cygnus.com"
> via SMTP by localhost.cygnus.com, id smtpdk71192; Mon Mar 27 18:40:41 2000
> Received: from runyon.cygnus.com
> by b1.cygnus.com (fetchmail-4.5.4 POP3)
> for <ac131313/localhost> (multi-drop); Mon, 27 Mar 2000 18:40:41 EST
> Received: from sourceware.cygnus.com (sourceware.cygnus.com [205.180.83.71])
> by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with SMTP id AAA10650
> for <ac131313@cygnus.com>; Mon, 27 Mar 2000 00:39:28 -0800 (PST)
> Received: (qmail 14396 invoked by alias); 27 Mar 2000 08:39:27 -0000
> Received: (qmail 14374 invoked from network); 27 Mar 2000 08:39:21 -0000
> Received: from andrew1.lnk.telstra.net (139.130.51.121)
> by sourceware.cygnus.com with SMTP; 27 Mar 2000 08:39:21 -0000
> Received: (from uucp@localhost)
> by andrew1.lnk.telstra.net (8.9.3/8.9.3) id SAA71171;
> Mon, 27 Mar 2000 18:37:27 +1000 (EST)
> (envelope-from ac131313@cygnus.com)
> Received: from localhost.cygnus.com(127.0.0.1), claiming to be "cygnus.com"
> via SMTP by localhost.cygnus.com, id smtpdA71169; Mon Mar 27 18:37:22 2000
> Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm
> Precedence: bulk
> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-ac131313=cygnus.com@sourceware.cygnus.com>
> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.cygnus.com>
> List-Archive: <http://sourceware.cygnus.com/ml/gdb-patches/>
> List-Post: <mailto:gdb-patches@sourceware.cygnus.com>
> List-Help: <mailto:gdb-patches-help@sourceware.cygnus.com>, <http://sourceware.cygnus.com/ml/#faqs>
> Sender: gdb-patches-owner@sourceware.cygnus.com
> Delivered-To: mailing list gdb-patches@sourceware.cygnus.com
> Message-ID: <38DF1DC2.17D53B85@cygnus.com>
> Date: Mon, 27 Mar 2000 18:37:22 +1000
> From: Andrew Cagney <ac131313@cygnus.com>
> Organization: Cygnus Solutions
> X-Mailer: Mozilla 4.6 [en] (X11; I; FreeBSD 3.4-RELEASE i386)
> X-Accept-Language: en
> MIME-Version: 1.0
> To: green@redhat.com
> CC: gdb-patches@sourceware.cygnus.com, jimb@cygnus.com, tromey@cygnus.com
> Subject: Re: Patch: handle N_MAIN stab
> References: <200003051039.CAA04980@hoser.cygnus.com>
> Content-Transfer-Encoding: 7bit
> Content-Type: text/plain; charset=us-ascii
> X-Mozilla-Status2: 00000000
>
> FYI,
>
> I think this patch slipped into limbo as it tweeks a number of files.
>
> I believe JimK identified a memory leak.
> For my part, I'd suggest ``main_name ()'' (or what ever) in symtab.[hc]
> or source.h (anyway somewhere more applicable then defs.h which as
> enough fluff :-).
>
> enjoy,
> Andrew
>
>
> > 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
>
>