* [PATCH] DW_AT_calling_convention support REV 2
@ 2002-07-10 11:41 Petr Sorfa
2002-07-10 11:47 ` Daniel Jacobowitz
0 siblings, 1 reply; 7+ messages in thread
From: Petr Sorfa @ 2002-07-10 11:41 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1507 bytes --]
Hi,
Revised patch for supporting DW_AT_calling_convention. This helps GDB
identify the "main" program for languages that do not have a starting
subroutine called "main". It adds a new API set for keeping track of the
symbol associated with "main". Note that there are 3 checks for
DW_AT_calling_convention. They are all necessary as they are detected at
different times when processing program debug information.
2002-07-10 Petr Sorfa (petrs@caldera.com)
* dwarf2read.c (read_subroutine_type): Expanded to recognize
the DW_AT_calling_convention DWARF attribute and for
DW_CC_program and calls set_main_name ().
(read_partial_die): Now recognizes the
DW_AT_calling_convention attribute and calls set_main_name().
(new_symbol): Checks whether the new symbol has a die entry
for DW_AT_calling_convention and calls set_main_symbol() for
DW_CC_program.
* symtab.h (set_main_symbol):
(get_main_symbol):
(is_main_symbol): Added extern prototypes for these dealing
with setting the ``main'' symbol.
* symtab.c (symbol_of_main): New static variable that points to
the current ``main'' symbol.
(set_main_symbol): New function that assigns a value to
symbol_of_main.
(get_main_symbol): Returns the value of symbol_of_main.
(is_main_symbol): Determines whether a given symbol is
equivalent to the "main" symbol.
[-- Attachment #2: calling_convention_rev2.patch --]
[-- Type: text/plain, Size: 5905 bytes --]
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.33
diff -c -p -r1.33 symtab.h
*** symtab.h 28 Jun 2002 22:09:11 -0000 1.33
--- symtab.h 10 Jul 2002 17:56:00 -0000
*************** extern struct cleanup *make_cleanup_free
*** 1392,1395 ****
--- 1392,1403 ----
extern void set_main_name (const char *name);
extern /*const*/ char *main_name (void);
+ /* The symbol associated with the ``main'' function. The return
+ value of get_main_symbol() can be NULL.
+ is_main_symbol() returns a non-zero value if the checked symbol
+ is equivalent to the ``main'' symbol */
+ extern void set_main_symbol (struct symbol *main_symbol);
+ extern struct symbol *get_main_symbol (void);
+ extern int is_main_symbol (struct symbol *check_symbol);
+
#endif /* !defined(SYMTAB_H) */
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.64
diff -c -p -r1.64 symtab.c
*** symtab.c 4 Jul 2002 15:22:42 -0000 1.64
--- symtab.c 10 Jul 2002 17:56:00 -0000
*************** decode_line_spec (char *string, int funf
*** 3954,3959 ****
--- 3954,3960 ----
/* Track MAIN */
static char *name_of_main;
+ static struct symbol *symbol_of_main = NULL;
void
set_main_name (const char *name)
*************** main_name (void)
*** 3978,3983 ****
--- 3979,4007 ----
return "main";
}
+ /* Set the symbol associated with the ``main'' function */
+ void
+ set_main_symbol (struct symbol *main_symbol)
+ {
+ symbol_of_main = main_symbol;
+ }
+
+ /* Retrieve the symbol associated with the ``main'' function.
+ Note that the return value can be NULL unlike main_name() */
+ struct symbol *
+ get_main_symbol (void)
+ {
+ return symbol_of_main;
+ }
+
+ /* Determine whether the symbol passed is equivalent to
+ the ``main'' symbol. Returns 0 if not or if there is no ``main''
+ symbol set. */
+ int
+ is_main_symbol (struct symbol *check_symbol)
+ {
+ return (check_symbol == NULL ? 0 : symbol_of_main == check_symbol);
+ }
void
_initialize_symtab (void)
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.60
diff -c -p -r1.60 dwarf2read.c
*** dwarf2read.c 22 Jun 2002 00:05:59 -0000 1.60
--- dwarf2read.c 10 Jul 2002 17:56:02 -0000
*************** read_subroutine_type (struct die_info *d
*** 3026,3031 ****
--- 3026,3052 ----
|| cu_language == language_cplus)
TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
+ /* Check for the calling convention. A DW_CC_program indicates that
+ the subroutine is the the "main" of the program. This needs
+ to be set for languages that don't have a predefined name
+ for the starting subroutines, such as FORTRAN. */
+ attr = dwarf_attr (die, DW_AT_calling_convention);
+ if (attr && (DW_UNSND (attr) != 0))
+ {
+ switch (DW_UNSND (attr))
+ {
+ case DW_CC_program:
+ /* Set this subroutine as the "main" subroutine
+ for the program. */
+ set_main_name (TYPE_NAME (ftype));
+ break;
+ case DW_CC_normal:
+ case DW_CC_nocall:
+ default:
+ break;
+ }
+ }
+
if (die->has_children)
{
struct die_info *child_die;
*************** read_partial_die (struct partial_die_inf
*** 3414,3419 ****
--- 3435,3441 ----
int found_spec_attr = 0;
int has_low_pc_attr = 0;
int has_high_pc_attr = 0;
+ int is_main_program = 0;
*part_die = zeroed_partial_die;
abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
*************** read_partial_die (struct partial_die_inf
*** 3446,3451 ****
--- 3468,3485 ----
if (part_die->name == NULL)
part_die->name = DW_STRING (&attr);
break;
+ case DW_AT_calling_convention:
+ switch (DW_UNSND (&attr))
+ {
+ case DW_CC_program:
+ is_main_program = 1;
+ break;
+ case DW_CC_normal:
+ case DW_CC_nocall:
+ default:
+ break;
+ }
+ break;
case DW_AT_MIPS_linkage_name:
part_die->name = DW_STRING (&attr);
break;
*************** read_partial_die (struct partial_die_inf
*** 3491,3496 ****
--- 3525,3537 ----
}
}
+ /* Set the ``main'' name after attribs have been processed as the
+ ordering of attributes is not guaranteed. */
+ if (is_main_program)
+ {
+ set_main_name (part_die->name);
+ }
+
/* If we found a reference attribute and the die has no name, try
to find a name in the referred to die. */
*************** new_symbol (struct die_info *die, struct
*** 4542,4547 ****
--- 4583,4611 ----
SYMBOL_TYPE (sym) = type;
else
SYMBOL_TYPE (sym) = die_type (die, objfile, cu_header);
+
+ /* Check for the calling convention. A DW_CC_program indicates that
+ the subroutine is the the "main" of the program. This needs
+ to be set for languages that don't have a predefined name
+ for the starting subroutines, such as FORTRAN. */
+ attr = dwarf_attr (die, DW_AT_calling_convention);
+ if (attr && (DW_UNSND (attr) != 0))
+ {
+ switch (DW_UNSND (attr))
+ {
+ case DW_CC_program:
+ /* Set this subroutine as the "main" subroutine
+ for the program. */
+ set_main_name (name);
+ set_main_symbol (sym);
+ break;
+ case DW_CC_normal:
+ case DW_CC_nocall:
+ default:
+ break;
+ }
+ }
+
attr = dwarf_attr (die, DW_AT_decl_line);
if (attr)
{
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DW_AT_calling_convention support REV 2
2002-07-10 11:41 [PATCH] DW_AT_calling_convention support REV 2 Petr Sorfa
@ 2002-07-10 11:47 ` Daniel Jacobowitz
2002-07-10 12:32 ` Petr Sorfa
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Jacobowitz @ 2002-07-10 11:47 UTC (permalink / raw)
To: Petr Sorfa; +Cc: gdb-patches
On Wed, Jul 10, 2002 at 02:44:56PM -0400, Petr Sorfa wrote:
> Hi,
>
> Revised patch for supporting DW_AT_calling_convention. This helps GDB
> identify the "main" program for languages that do not have a starting
> subroutine called "main". It adds a new API set for keeping track of the
> symbol associated with "main". Note that there are 3 checks for
> DW_AT_calling_convention. They are all necessary as they are detected at
> different times when processing program debug information.
I wasn't quite clear... there's one thing that should be different.
> + /* Determine whether the symbol passed is equivalent to
> + the ``main'' symbol. Returns 0 if not or if there is no ``main''
> + symbol set. */
> + int
> + is_main_symbol (struct symbol *check_symbol)
> + {
> + return (check_symbol == NULL ? 0 : symbol_of_main == check_symbol);
> + }
>
> void
> _initialize_symtab (void)
I was thinking like:
int
is_main_symbol (struct symbol *check_symbol)
{
if (symbol_of_main && symbol_of_main == check_symbol)
return 1;
else if (strcmp (SYMBOL_NAME (check_symbol), get_main_name ()) == 0)
return 1;
return 0;
}
And then change all callers of get_main_name () to use this.
(Note that this requires being careful if symbol_of_main gets
unloaded and we load a C program afterwards!)
Make sense? Sound reasonable?
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DW_AT_calling_convention support REV 2
2002-07-10 11:47 ` Daniel Jacobowitz
@ 2002-07-10 12:32 ` Petr Sorfa
2002-07-10 12:41 ` Daniel Jacobowitz
0 siblings, 1 reply; 7+ messages in thread
From: Petr Sorfa @ 2002-07-10 12:32 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
Hi Daniel,
> > Revised patch for supporting DW_AT_calling_convention. This helps GDB
> > identify the "main" program for languages that do not have a starting
> > subroutine called "main". It adds a new API set for keeping track of the
> > symbol associated with "main". Note that there are 3 checks for
> > DW_AT_calling_convention. They are all necessary as they are detected at
> > different times when processing program debug information.
>
> I wasn't quite clear... there's one thing that should be different.
>
> > + /* Determine whether the symbol passed is equivalent to
> > + the ``main'' symbol. Returns 0 if not or if there is no ``main''
> > + symbol set. */
> > + int
> > + is_main_symbol (struct symbol *check_symbol)
> > + {
> > + return (check_symbol == NULL ? 0 : symbol_of_main == check_symbol);
> > + }
> >
> > void
> > _initialize_symtab (void)
>
> I was thinking like:
>
> int
> is_main_symbol (struct symbol *check_symbol)
> {
> if (symbol_of_main && symbol_of_main == check_symbol)
> return 1;
> else if (strcmp (SYMBOL_NAME (check_symbol), get_main_name ()) == 0)
> return 1;
> return 0;
> }
Good, I agree, that makes it more generic. Need to check for
check_symbol for NULL as this might tank GDB at the second if.
> And then change all callers of get_main_name () to use this.
>
> (Note that this requires being careful if symbol_of_main gets
> unloaded and we load a C program afterwards!)
>
> Make sense? Sound reasonable?
Um, you've lost me. There is no get_main_name() function, do you mean
get_main_symbol() or main_name()? I still not sure what the callers of
the function should do.
Although, I do agree that the patch should catch unloading the
main_symbol, but how?
Petr
>
> --
> Daniel Jacobowitz Carnegie Mellon University
> MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DW_AT_calling_convention support REV 2
2002-07-10 12:32 ` Petr Sorfa
@ 2002-07-10 12:41 ` Daniel Jacobowitz
2002-07-10 14:06 ` Petr Sorfa
2002-07-11 8:07 ` Petr Sorfa
0 siblings, 2 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2002-07-10 12:41 UTC (permalink / raw)
To: Petr Sorfa; +Cc: gdb-patches
On Wed, Jul 10, 2002 at 03:39:56PM -0400, Petr Sorfa wrote:
> Hi Daniel,
>
> > > Revised patch for supporting DW_AT_calling_convention. This helps GDB
> > > identify the "main" program for languages that do not have a starting
> > > subroutine called "main". It adds a new API set for keeping track of the
> > > symbol associated with "main". Note that there are 3 checks for
> > > DW_AT_calling_convention. They are all necessary as they are detected at
> > > different times when processing program debug information.
> >
> > I wasn't quite clear... there's one thing that should be different.
> >
> > > + /* Determine whether the symbol passed is equivalent to
> > > + the ``main'' symbol. Returns 0 if not or if there is no ``main''
> > > + symbol set. */
> > > + int
> > > + is_main_symbol (struct symbol *check_symbol)
> > > + {
> > > + return (check_symbol == NULL ? 0 : symbol_of_main == check_symbol);
> > > + }
> > >
> > > void
> > > _initialize_symtab (void)
> >
> > I was thinking like:
> >
> > int
> > is_main_symbol (struct symbol *check_symbol)
> > {
> > if (symbol_of_main && symbol_of_main == check_symbol)
> > return 1;
> > else if (strcmp (SYMBOL_NAME (check_symbol), get_main_name ()) == 0)
> > return 1;
> > return 0;
> > }
> Good, I agree, that makes it more generic. Need to check for
> check_symbol for NULL as this might tank GDB at the second if.
Why should NULL be a legitimate argument? Calling the function without
a symbol is useless...
> > And then change all callers of get_main_name () to use this.
> >
> > (Note that this requires being careful if symbol_of_main gets
> > unloaded and we load a C program afterwards!)
> >
> > Make sense? Sound reasonable?
> Um, you've lost me. There is no get_main_name() function, do you mean
> get_main_symbol() or main_name()? I still not sure what the callers of
> the function should do.
main_name(), I assume. Basically I would like everywhere that
currently checks by a strcmp/STREQ with main_name() to use
is_main_symbol () instead, etc. Things that call lookup_symbol on
main_name() should just use get_main_symbol () if possible. Then
set_main_name () could include calling lookup_symbol(main_name()), so
that get_main_symbol would always be valid, etc....
> Although, I do agree that the patch should catch unloading the
> main_symbol, but how?
I'm not sure :( Is there a hook for when object files are unloaded?
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DW_AT_calling_convention support REV 2
2002-07-10 12:41 ` Daniel Jacobowitz
@ 2002-07-10 14:06 ` Petr Sorfa
2002-07-11 8:07 ` Petr Sorfa
1 sibling, 0 replies; 7+ messages in thread
From: Petr Sorfa @ 2002-07-10 14:06 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
Hi,
> > Good, I agree, that makes it more generic. Need to check for
> > check_symbol for NULL as this might tank GDB at the second if.
>
> Why should NULL be a legitimate argument? Calling the function without
> a symbol is useless...
Just error trapping. In case something goes wrong and a NULL pointer
gets accidentally passed.
> > > And then change all callers of get_main_name () to use this.
> > >
> > > (Note that this requires being careful if symbol_of_main gets
> > > unloaded and we load a C program afterwards!)
> > >
> > > Make sense? Sound reasonable?
> > Um, you've lost me. There is no get_main_name() function, do you mean
> > get_main_symbol() or main_name()? I still not sure what the callers of
> > the function should do.
>
> main_name(), I assume. Basically I would like everywhere that
> currently checks by a strcmp/STREQ with main_name() to use
> is_main_symbol () instead, etc. Things that call lookup_symbol on
> main_name() should just use get_main_symbol () if possible. Then
> set_main_name () could include calling lookup_symbol(main_name()), so
> that get_main_symbol would always be valid, etc....
Ok, got it.
> > Although, I do agree that the patch should catch unloading the
> > main_symbol, but how?
>
> I'm not sure :( Is there a hook for when object files are unloaded?
Nope. In the cu_header patch, I have a hook from elfread.c to
dwarf2read.c to clear up stuff when a new program is about to be
debugged. The function will be called dwarf_init (). But as for a
generic solution..
Petr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DW_AT_calling_convention support REV 2
2002-07-10 12:41 ` Daniel Jacobowitz
2002-07-10 14:06 ` Petr Sorfa
@ 2002-07-11 8:07 ` Petr Sorfa
2002-07-11 9:22 ` Daniel Jacobowitz
1 sibling, 1 reply; 7+ messages in thread
From: Petr Sorfa @ 2002-07-11 8:07 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
Hi Daniel,
> main_name(), I assume. Basically I would like everywhere that
> currently checks by a strcmp/STREQ with main_name() to use
> is_main_symbol () instead, etc. Things that call lookup_symbol on
> main_name() should just use get_main_symbol () if possible. Then
> set_main_name () could include calling lookup_symbol(main_name()), so
> that get_main_symbol would always be valid, etc....
Unforuntately after looking at this I realized this will not work always
correctly. It is quite possible that a symbol is not created for "main"
until much later. There are calls to set_main_name() before the symbol
is created, so your proposition to do a lookup_symbol() in
set_main_name() will not work in all cases.
I suggest that the get_main_symbol() is altered to your suggestions, to
which I want to add further checks such as ensuring that the main name
is equal to the main symbol's name.
If this is ok with you, I'll do a rev 3 patch for this and submit it.
Petr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DW_AT_calling_convention support REV 2
2002-07-11 8:07 ` Petr Sorfa
@ 2002-07-11 9:22 ` Daniel Jacobowitz
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2002-07-11 9:22 UTC (permalink / raw)
To: Petr Sorfa; +Cc: gdb-patches
On Thu, Jul 11, 2002 at 11:09:37AM -0400, Petr Sorfa wrote:
> Hi Daniel,
>
> > main_name(), I assume. Basically I would like everywhere that
> > currently checks by a strcmp/STREQ with main_name() to use
> > is_main_symbol () instead, etc. Things that call lookup_symbol on
> > main_name() should just use get_main_symbol () if possible. Then
> > set_main_name () could include calling lookup_symbol(main_name()), so
> > that get_main_symbol would always be valid, etc....
> Unforuntately after looking at this I realized this will not work always
> correctly. It is quite possible that a symbol is not created for "main"
> until much later. There are calls to set_main_name() before the symbol
> is created, so your proposition to do a lookup_symbol() in
> set_main_name() will not work in all cases.
>
> I suggest that the get_main_symbol() is altered to your suggestions, to
> which I want to add further checks such as ensuring that the main name
> is equal to the main symbol's name.
>
> If this is ok with you, I'll do a rev 3 patch for this and submit it.
That's unfortunate, but I guess not surprising... yes, your solution
sounds good to me.
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2002-07-11 15:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-10 11:41 [PATCH] DW_AT_calling_convention support REV 2 Petr Sorfa
2002-07-10 11:47 ` Daniel Jacobowitz
2002-07-10 12:32 ` Petr Sorfa
2002-07-10 12:41 ` Daniel Jacobowitz
2002-07-10 14:06 ` Petr Sorfa
2002-07-11 8:07 ` Petr Sorfa
2002-07-11 9:22 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox