* [RFA] Handle GPC specific name for main function
@ 2007-10-03 9:31 Pierre Muller
2007-10-05 18:16 ` Joel Brobecker
0 siblings, 1 reply; 12+ messages in thread
From: Pierre Muller @ 2007-10-03 9:31 UTC (permalink / raw)
To: gdb-patches; +Cc: gpc
This is my final patch to be able to
detect the fact that GPC was used to compile
the main procedure and set the name of that main
procedure (which is either "pascal_main_program"
or "_p__M0_main_program").
The whole thread started with
http://sourceware.org/ml/gdb-patches/2007-09/msg00373.html
Is it OK to commit?
Pierre Muller
Pascal language maintainer.
ChangeLog entry:
2007-10-03 Pierre Muller <muller@ics.u-strasbg.fr>
* p-lang.h (pascal_main_name): New function.
p-lang.c (GPC_P_INITIALIZE, GPC_MAIN_PROGRAM_NAME_1),
(GPC_MAIN_PROGRAM_NAME_2): New char array constants
corresponding to the three minimal symbols used
by GPC compiler.
(pascal_main_name): Try to find minimal symbol
corresponding to the entry of GPC compiled programs.
symtab.c: New include p-lang.h.
(find_main_name): Try to find pascal specific main name
by calling pascal_main_name.
* Makefile.in (symtab.o): Add dependency on p-lang header.
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 3 Oct 2007 09:21:58 -0000
@@ -21,6 +21,9 @@
struct value;
+/* Defined in p-lang.c */
+extern char *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 3 Oct 2007 09:21:58 -0000
@@ -35,6 +35,63 @@
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. */
+
+char *
+pascal_main_name (void)
+{
+ struct minimal_symbol *msym;
+
+ msym = lookup_minimal_symbol (GPC_P_INITIALIZE, NULL, NULL);
+
+ /* If '_p_initialize' was not found,
+ the program doesn't seem to be compiled with GPC.
+ Thus default name "main" should work. */
+ if (msym == NULL)
+ return NULL;
+
+ msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_1, NULL, NULL);
+
+ if (msym != NULL)
+ {
+ return (char *)GPC_MAIN_PROGRAM_NAME_1;
+ }
+
+ msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_2, NULL, NULL);
+
+ if (msym != NULL)
+ {
+ return (char *)GPC_MAIN_PROGRAM_NAME_2;
+ }
+
+/* No known entry procedure found, use default 'main' name.
+ According to Waldek Hebish, this should not happen for any GPC version
+ after June 2000 and up to 2007-09-27. */
+ 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 3 Oct 2007 09:21:59 -0000
@@ -40,6 +40,7 @@
#include "filenames.h" /* for FILENAME_CMP */
#include "objc-lang.h"
#include "ada-lang.h"
+#include "p-lang.h"
#include "hashtab.h"
@@ -4151,6 +4152,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 3 Oct 2007 09:22:00 -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)
\
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Handle GPC specific name for main function
2007-10-03 9:31 [RFA] Handle GPC specific name for main function Pierre Muller
@ 2007-10-05 18:16 ` Joel Brobecker
2007-10-06 7:24 ` Eli Zaretskii
0 siblings, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2007-10-05 18:16 UTC (permalink / raw)
To: Pierre Muller; +Cc: gdb-patches
Hi Pierre,
> 2007-10-03 Pierre Muller <muller@ics.u-strasbg.fr>
>
> * p-lang.h (pascal_main_name): New function.
> p-lang.c (GPC_P_INITIALIZE, GPC_MAIN_PROGRAM_NAME_1),
> (GPC_MAIN_PROGRAM_NAME_2): New char array constants
> corresponding to the three minimal symbols used
> by GPC compiler.
> (pascal_main_name): Try to find minimal symbol
> corresponding to the entry of GPC compiled programs.
> symtab.c: New include p-lang.h.
> (find_main_name): Try to find pascal specific main name
> by calling pascal_main_name.
> * Makefile.in (symtab.o): Add dependency on p-lang header.
This is mostly OK. I feel like I am being a perfectionist on you,
and I apologize, but I think I might have missed something that
feels wrong somehow: You're having to cast your global static const
char into (char *) inside pascal_main_name. I can tell from the code
that everything will be fine, but perhaps we could do better. What
do others think of this cast?
static const char GPC_MAIN_PROGRAM_NAME_1[]
= "_p__M0_main_program";
char *
pascal_main_name (void)
{
[...]
return (char *) GPC_MAIN_PROGRAM_NAME_1[];
}
One way I can see to avoid having to do the cast is to return
the SYMBOL_LINKAGE_NAME of the msym we found. Something like this:
char *
pascal_main_name (void)
{
struct minimal_symbol *msym;
msym = lookup_minimal_symbol (GPC_P_INITIALIZE, NULL, NULL);
/* If '_p_initialize' was not found,
the program doesn't seem to be compiled with GPC.
Thus default name "main" should work. */
if (msym == NULL)
return NULL;
msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_1, NULL, NULL);
if (msym == NULL)
msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_2, NULL, NULL);
if (msym != NULL)
return SYMBOL_LINKAGE_NAME (msym);
return NULL;
}
This is only a small detail, and I can't see anything wrong happening
with your patch, so I suggest you go ahead and commit the change, and
we can adjust it if others also feel the same way.
Just one adjustment:
> +/* No known entry procedure found, use default 'main' name.
> + According to Waldek Hebish, this should not happen for any GPC version
> + after June 2000 and up to 2007-09-27. */
This comment assumes that the main program is actually always written
in Pascal. But this is not true. This function will also be called for
programs written in any other language. I suggest:
/* No known entry procedure found. The main program is probably
not written in Pascal. */
The rest of the patch is great!
Thank you,
--
Joel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Handle GPC specific name for main function
2007-10-05 18:16 ` Joel Brobecker
@ 2007-10-06 7:24 ` Eli Zaretskii
2007-10-07 7:17 ` Joel Brobecker
0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2007-10-06 7:24 UTC (permalink / raw)
To: Joel Brobecker; +Cc: muller, gdb-patches
> Date: Fri, 5 Oct 2007 11:16:20 -0700
> From: Joel Brobecker <brobecker@adacore.com>
> Cc: gdb-patches@sourceware.org
>
> This is mostly OK. I feel like I am being a perfectionist on you,
> and I apologize, but I think I might have missed something that
> feels wrong somehow: You're having to cast your global static const
> char into (char *) inside pascal_main_name. I can tell from the code
> that everything will be fine, but perhaps we could do better. What
> do others think of this cast?
>
> static const char GPC_MAIN_PROGRAM_NAME_1[]
> = "_p__M0_main_program";
>
> char *
> pascal_main_name (void)
> {
> [...]
> return (char *) GPC_MAIN_PROGRAM_NAME_1[];
> }
Yuck! Can't we make pascal_main_name return `const char *'? If not,
why not?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Handle GPC specific name for main function
2007-10-06 7:24 ` Eli Zaretskii
@ 2007-10-07 7:17 ` Joel Brobecker
2007-10-07 19:25 ` Eli Zaretskii
0 siblings, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2007-10-07 7:17 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: muller, gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1346 bytes --]
Hi Eli,
> Yuck! Can't we make pascal_main_name return `const char *'? If not,
> why not?
That's a good idea. What do you think about this revised version
of Pierre's patch?
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): New function.
* Makefile.in (symtab.o): Add dependency on p-lang.h.
Pierre,
This patch also implements the adjustments in the comments that
I suggested. The way you wrote these commments made me think that
you were implicitly thinking that your function is called only
when the program is written in Pascal (and only in Pascal). But
in fact, this is not the case, and the program could actually be
multi-language! I also noticed some formatting issues, which I
also fixed.
I also just now noticed that I had some comments on your ChangeLog
entry. Above is how I would write it: You were missing the '*' for
each new file; And I made the text more concise (no need to explain
what the function does for instance).
I should have noticed that the first time around, but being new at
reviewing patch, I'm still learning.
--
Joel
[-- Attachment #2: pascal.diff --]
[-- Type: text/plain, Size: 3498 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 7 Oct 2007 07:13:41 -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 7 Oct 2007 07:13:41 -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: 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 7 Oct 2007 07:13:42 -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) \
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Handle GPC specific name for main function
2007-10-07 7:17 ` Joel Brobecker
@ 2007-10-07 19:25 ` Eli Zaretskii
2007-10-08 6:35 ` Joel Brobecker
0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2007-10-07 19:25 UTC (permalink / raw)
To: Joel Brobecker; +Cc: muller, gdb-patches
> Date: Sun, 7 Oct 2007 00:17:13 -0700
> From: Joel Brobecker <brobecker@adacore.com>
> Cc: muller@ics.u-strasbg.fr, gdb-patches@sourceware.org
>
> > Yuck! Can't we make pascal_main_name return `const char *'? If not,
> > why not?
>
> That's a good idea. What do you think about this revised version
> of Pierre's patch?
Fine with me; that's what I had in mind.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Handle GPC specific name for main function
2007-10-07 19:25 ` Eli Zaretskii
@ 2007-10-08 6:35 ` Joel Brobecker
2007-10-08 7:35 ` Pierre Muller
0 siblings, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2007-10-08 6:35 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: muller, gdb-patches
[-- 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) \
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [RFA] Handle GPC specific name for main function
2007-10-08 6:35 ` Joel Brobecker
@ 2007-10-08 7:35 ` Pierre Muller
2007-10-08 15:14 ` Joel Brobecker
0 siblings, 1 reply; 12+ messages in thread
From: Pierre Muller @ 2007-10-08 7:35 UTC (permalink / raw)
To: 'Joel Brobecker', 'Eli Zaretskii'; +Cc: gdb-patches
Hi Joel,
I am sorry to be so late to reply to your
comments, but I have currently no internet access
at home :(
About your changes:
1) Change of function type to "const char *"
Chainging the return type of
"pascal_main_name" to "const char *" seems fine for me,
but in the function "find_main_name",
there is first a call to ada_main_name
which is a "char *" function, and is now
assigned to a "const char *", as you changed the type of
"new_main_name" variable. My limited knowledge of
the subtle differences between "const char *" and "char *"
explains why I missed it at the start, but also
lets me state that I have no idea if changing the return type
of "ada_main_name" is correct, or if doing the typecasting on
the line where "ada_main_name" is called.
Wouldn't it be better to leave the new_main_name type
unchanged, and do a type cast either when calling "pascal_main_name"
or inside "pascal_main_name" if we decide to leave it as a
"char *".
2) Your change to the final comment inside "pascal_main_name":
The main point here is that this function is only useful for
the GNU pascal compiler (GPC) which gives a special symbol name
to the main procedure inside the main source.
This is not the case for the Free Pascal compiler,
another freeware, and I happen to be part of the core developer
team of Free Pascal, thus your comment is misleading
+ /* No known entry procedure found, the main program is probably
+ not in pascal. */
I would propose
+ /* No known entry procedure found, the main program is probably
+ not compiled by GPC. */
Thank you very much for taking the time
to review this patch,
Pierre Muller
Pascal language maintainer.
> -----Original Message-----
> From: Joel Brobecker [mailto:brobecker@adacore.com]
> Sent: Monday, October 08, 2007 8:35 AM
> To: Eli Zaretskii
> Cc: muller@ics.u-strasbg.fr; gdb-patches@sourceware.org
> Subject: Re: [RFA] Handle GPC specific name for main function
>
> > 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Handle GPC specific name for main function
2007-10-08 7:35 ` Pierre Muller
@ 2007-10-08 15:14 ` Joel Brobecker
2007-10-08 15:43 ` [RFA-2] " Pierre Muller
0 siblings, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2007-10-08 15:14 UTC (permalink / raw)
To: Pierre Muller; +Cc: 'Eli Zaretskii', gdb-patches
Hi Pierre,
Nothing like refreshing my confused knowledge of const-ification
in C while admiring the sunrise :). I'm an Ada programer more than
a C programer, so I hope I haven't contributed to your confusion.
> 1) Change of function type to "const char *"
> Chainging the return type of
> "pascal_main_name" to "const char *" seems fine for me,
And that's actually what we should do. I suggested "const char const *",
but in fact, I don't know what I was thinking, the latter is equivalent.
So just change the return type of function pascal_main_name to "const
char *".
You'll need to adjust the type of new_main_name in find_main_name to
"const char *" too. This is match the type returned by your function.
It is fine to leave ada_main_name return "char *" for now, I will
adjust it as a separate patch later
> but in the function "find_main_name", there is first a call to
> ada_main_name which is a "char *" function, and is now assigned to a
> "const char *", as you changed the type of "new_main_name" variable.
As said above, this should be fine. All we're doing when we say that
new_main_name is a "const char *" is that the contents of new_main_name
must not be changed. The compiler will check that for us. Assigning
a "char *" to new_main_name does not violate this restriction.
> + /* No known entry procedure found, the main program is probably
> + not compiled by GPC. */
This is fine as well.
--
Joel
^ permalink raw reply [flat|nested] 12+ messages in thread
* [RFA-2] Handle GPC specific name for main function
2007-10-08 15:14 ` Joel Brobecker
@ 2007-10-08 15:43 ` Pierre Muller
2007-10-08 15:45 ` Pierre Muller
2007-10-08 17:24 ` Joel Brobecker
0 siblings, 2 replies; 12+ messages in thread
From: Pierre Muller @ 2007-10-08 15:43 UTC (permalink / raw)
To: 'Joel Brobecker'; +Cc: 'Eli Zaretskii', gdb-patches, gpc
Thanks to Joel for all his contribution,
I resubmit a modified version, which is
the same as Joel proposed, to the exception that
I used "const char *" instead of "const char const *"
that I did not find anywhere else in the GDB sources
and seems really strange to me...
I also modified the final comment inside pascal_main_name.
ChangeLog entry:
2007-10-08 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.
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 15:41:43 -0000
@@ -21,6 +21,9 @@
struct value;
+/* Defined in p-lang.c */
+extern const char *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 15:41:43 -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 *
+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 compiled with GPC. */
+ 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 15:41:44 -0000
@@ -40,6 +40,7 @@
#include "filenames.h" /* for FILENAME_CMP */
#include "objc-lang.h"
#include "ada-lang.h"
+#include "p-lang.h"
#include "hashtab.h"
@@ -4126,7 +4127,7 @@ set_main_name (const char *name)
static void
find_main_name (void)
{
- char *new_main_name;
+ const char *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 +4152,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.941
diff -u -p -r1.941 Makefile.in
--- Makefile.in 8 Oct 2007 15:09:04 -0000 1.941
+++ Makefile.in 8 Oct 2007 15:41:45 -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)
\
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [RFA-2] Handle GPC specific name for main function
2007-10-08 15:43 ` [RFA-2] " Pierre Muller
@ 2007-10-08 15:45 ` Pierre Muller
2007-10-08 17:24 ` Joel Brobecker
1 sibling, 0 replies; 12+ messages in thread
From: Pierre Muller @ 2007-10-08 15:45 UTC (permalink / raw)
To: 'Pierre Muller', 'Joel Brobecker'
Cc: 'Eli Zaretskii', gdb-patches, gpc
Whoops, I forgot to tell you
that this patch does reduce the number of failures
for GNU pascal compiler
on the newly added gdb.pascal directory in the testsuite.
I will try to run a complete testsuite,
Pierre
> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] On Behalf Of Pierre Muller
> Sent: Monday, October 08, 2007 5:43 PM
> To: 'Joel Brobecker'
> Cc: 'Eli Zaretskii'; gdb-patches@sourceware.org; gpc@gnu.de
> Subject: [RFA-2] Handle GPC specific name for main function
>
> Thanks to Joel for all his contribution,
> I resubmit a modified version, which is
> the same as Joel proposed, to the exception that
> I used "const char *" instead of "const char const *"
> that I did not find anywhere else in the GDB sources
> and seems really strange to me...
> I also modified the final comment inside pascal_main_name.
>
>
>
> ChangeLog entry:
>
> 2007-10-08 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.
>
>
> 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 15:41:43 -0000
> @@ -21,6 +21,9 @@
>
> struct value;
>
> +/* Defined in p-lang.c */
> +extern const char *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 15:41:43 -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 *
> +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 compiled with GPC. */
> + 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 15:41:44 -0000
> @@ -40,6 +40,7 @@
> #include "filenames.h" /* for FILENAME_CMP */
> #include "objc-lang.h"
> #include "ada-lang.h"
> +#include "p-lang.h"
>
> #include "hashtab.h"
>
> @@ -4126,7 +4127,7 @@ set_main_name (const char *name)
> static void
> find_main_name (void)
> {
> - char *new_main_name;
> + const char *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 +4152,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.941
> diff -u -p -r1.941 Makefile.in
> --- Makefile.in 8 Oct 2007 15:09:04 -0000 1.941
> +++ Makefile.in 8 Oct 2007 15:41:45 -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)
> \
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA-2] Handle GPC specific name for main function
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
1 sibling, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2007-10-08 17:24 UTC (permalink / raw)
To: Pierre Muller; +Cc: 'Eli Zaretskii', gdb-patches, gpc
> 2007-10-08 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.
I've tested this patch for you. I couldn't test the pascal side of
it, but I figured you did for your other message. You can check
this in, now.
Thanks,
--
Joel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA-2] Handle GPC specific name for main function
2007-10-08 17:24 ` Joel Brobecker
@ 2007-10-08 18:45 ` Joel Brobecker
0 siblings, 0 replies; 12+ messages in thread
From: Joel Brobecker @ 2007-10-08 18:45 UTC (permalink / raw)
To: Pierre Muller; +Cc: 'Eli Zaretskii', gdb-patches, gpc
> 2007-10-08 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.
I've tested this patch for you. I couldn't test the pascal side of
it, but I figured you did for your other message. You can check
this in, now.
Thanks,
--
Joel
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2007-10-08 18:09 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-03 9:31 [RFA] Handle GPC specific name for main function 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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox