Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: muller@ics.u-strasbg.fr, gdb-patches@sourceware.org
Subject: Re: [RFA] Handle GPC specific name for main function
Date: Mon, 08 Oct 2007 06:35:00 -0000	[thread overview]
Message-ID: <20071008063451.GI3570@adacore.com> (raw)
In-Reply-To: <utzp2afrj.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

> Fine with me; that's what I had in mind.

Excellent. Here is the complete patch, I forgot to include the symtab.c
part...

2007-10-07  Pierre Muller  <muller@ics.u-strasbg.fr>

        * p-lang.h (pascal_main_name): Add declaration.
        * p-lang.c (GPC_P_INITIALIZE, GPC_MAIN_PROGRAM_NAME_1)
        (GPC_MAIN_PROGRAM_NAME_2): New constants.
        (pascal_main_name): New function.
        * symtab.c: Include p-lang.h.
        (find_main_name): ADd call to pascal_main_name.
        * Makefile.in (symtab.o): Add dependency on p-lang.h.

Needs to be tested...

-- 
Joel

[-- Attachment #2: pascal.diff --]
[-- Type: text/plain, Size: 4376 bytes --]

Index: p-lang.h
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.h,v
retrieving revision 1.12
diff -u -p -r1.12 p-lang.h
--- p-lang.h	23 Aug 2007 18:08:36 -0000	1.12
+++ p-lang.h	8 Oct 2007 06:30:25 -0000
@@ -21,6 +21,9 @@
 
 struct value;
 
+/* Defined in p-lang.c */
+extern const char const *pascal_main_name (void);
+
 extern int pascal_parse (void);	/* Defined in p-exp.y */
 
 extern void pascal_error (char *);	/* Defined in p-exp.y */
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.33
diff -u -p -r1.33 p-lang.c
--- p-lang.c	23 Sep 2007 16:25:05 -0000	1.33
+++ p-lang.c	8 Oct 2007 06:30:25 -0000
@@ -35,6 +35,56 @@
 extern void _initialize_pascal_language (void);
 
 
+/* All GPC versions until now (2007-09-27) also define a symbol called
+   '_p_initialize'. Check for the presence of this symbol first.  */
+static const char GPC_P_INITIALIZE[] = "_p_initialize";
+
+/* The name of the symbol that GPC uses as the name of the main
+   procedure (since version 20050212).  */
+static const char GPC_MAIN_PROGRAM_NAME_1[] = "_p__M0_main_program";
+
+/* Older versions of GPC (versions older than 20050212) were using
+   a different name for the main procedure.  */
+static const char GPC_MAIN_PROGRAM_NAME_2[] = "pascal_main_program";
+
+/* Function returning the special symbol name used
+   by GPC for the main procedure in the main program
+   if it is found in minimal symbol list.
+   This function tries to find minimal symbols generated by GPC
+   so that it finds the even if the program was compiled
+   without debugging information.
+   According to information supplied by Waldeck Hebisch,
+   this should work for all versions posterior to June 2000. */
+
+const char const *
+pascal_main_name (void)
+{
+  struct minimal_symbol *msym;
+
+  msym = lookup_minimal_symbol (GPC_P_INITIALIZE, NULL, NULL);
+
+  /*  If '_p_initialize' was not found, the main program is likely not
+     written in Pascal.  */
+  if (msym == NULL)
+    return NULL;
+
+  msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_1, NULL, NULL);
+  if (msym != NULL)
+    {
+      return GPC_MAIN_PROGRAM_NAME_1;
+    }
+
+  msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_2, NULL, NULL);
+  if (msym != NULL)
+    {
+      return GPC_MAIN_PROGRAM_NAME_2;
+    }
+
+  /*  No known entry procedure found, the main program is probably
+      not in pascal.  */
+  return NULL;
+}
+
 /* Determines if type TYPE is a pascal string type.
    Returns 1 if the type is a known pascal type
    This function is used by p-valprint.c code to allow better string display.
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.165
diff -u -p -r1.165 symtab.c
--- symtab.c	24 Sep 2007 07:40:32 -0000	1.165
+++ symtab.c	8 Oct 2007 06:30:27 -0000
@@ -4126,7 +4126,7 @@ set_main_name (const char *name)
 static void
 find_main_name (void)
 {
-  char *new_main_name;
+  const char const *new_main_name;
 
   /* Try to see if the main procedure is in Ada.  */
   /* FIXME: brobecker/2005-03-07: Another way of doing this would
@@ -4151,6 +4151,13 @@ find_main_name (void)
       return;
     }
 
+  new_main_name = pascal_main_name ();
+  if (new_main_name != NULL)
+    { 
+      set_main_name (new_main_name);
+      return;
+    }
+
   /* The languages above didn't identify the name of the main procedure.
      Fallback to "main".  */
   set_main_name ("main");
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.939
diff -u -p -r1.939 Makefile.in
--- Makefile.in	27 Sep 2007 18:48:32 -0000	1.939
+++ Makefile.in	8 Oct 2007 06:30:27 -0000
@@ -2751,7 +2751,7 @@ symtab.o: symtab.c $(defs_h) $(symtab_h)
 	$(filenames_h) $(objc_lang_h) $(ada_lang_h) $(hashtab_h) \
 	$(gdb_obstack_h) $(block_h) $(dictionary_h) $(gdb_string_h) \
 	$(gdb_stat_h) $(cp_abi_h) $(observer_h) $(gdb_assert_h) \
-	$(solist_h) $(ada_lang_h)
+	$(solist_h) $(p_lang_h)
 target.o: target.c $(defs_h) $(gdb_string_h) $(target_h) $(gdbcmd_h) \
 	$(symtab_h) $(inferior_h) $(bfd_h) $(symfile_h) $(objfiles_h) \
 	$(gdb_wait_h) $(dcache_h) $(regcache_h) $(gdb_assert_h) $(gdbcore_h) \

  reply	other threads:[~2007-10-08  6:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-03  9:31 Pierre Muller
2007-10-05 18:16 ` Joel Brobecker
2007-10-06  7:24   ` Eli Zaretskii
2007-10-07  7:17     ` Joel Brobecker
2007-10-07 19:25       ` Eli Zaretskii
2007-10-08  6:35         ` Joel Brobecker [this message]
2007-10-08  7:35           ` Pierre Muller
2007-10-08 15:14             ` Joel Brobecker
2007-10-08 15:43               ` [RFA-2] " Pierre Muller
2007-10-08 15:45                 ` Pierre Muller
2007-10-08 17:24                 ` Joel Brobecker
2007-10-08 18:45                   ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071008063451.GI3570@adacore.com \
    --to=brobecker@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=muller@ics.u-strasbg.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox