This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA/RFC] New command: ``start''
> > We could get rid of the caching mechanism, and recompute name_of_main
> > everytime (unless found in the debug info), but I think that would be
> > very costly, especially with graphical front-ends that have a tendency
> > of asking for the callstack at every stop...
>
> I don't think it would be costly. However, I think it would be very
> confusing! Consider: we're in an Ada routine. We backtrace. This is
> the main program, so the backtrace stops at this procedure. We
> single-step into a C subroutine and backtrace; now the backtrace goes
> back to the Ada procedure and then back again further!
Yes, very confusing indeed.
> I'm having the same problem reviewing this that I did with
> SYMBOL_SEARCH_NAME: namely, you're introducing interfaces that don't
> exist in our Ada support files, without the Ada implementation of the
> interface. Could you show me what the Ada function for guessing the
> name of main does?
That's because the command name we've been using for that was "begin".
But people prefered "start" (which I like better too), so I changed
the name.
Here is how we find the name of the main procedure: We lookup a certain
symbol which is created by our binder, __gnat_ada_main_program_name.
This symbol points to a string holding the name of the main procedure.
You'll find the code in ada-lang.c:begin_command().
BTW: I think Paul was working on submitting a more recent version of
the ada-* files. I'll double-check with him.
> I think the best approach may be to iterate over the languages
> included in the object file, asking each of them whether this language
> appears to contain a main procedure. Or even to simply skip the
> langhook complexity and just call an Ada find-main function! For gcj
> I suspect we will just change the debug information.
I thought about several approaches along the same idea. One of them
was to implement a sniffing mechanism, with certain sniffers having
certain priorities. But you know, I really like the idea of dropping
the langhook, and just call the ada function. Something like this:
char *
main_name ()
{
/* If we found the name of main from the debug info, or
already looked it up, then return the name of main. */
if (name_of_main != NULL)
return name_of_main;
/* Is the main in Ada? */
tmp_main_name = ada_find_main_name ();
if (tmp_main_name != NULL)
{
set_main_name (tmp_main_name);
return name_of_main;
}
/* Is the main in Java? */
tmp_main_name = java_find_main_name ();
[etc...]
/* Fallback: main_name must be the usual "main". */
set_main_name ("main);
return name_of_main;
}
The only drawback I see from this is that I will need to include
ada-lang.h. It would have been nice to avoid this, which is possible
with the langhooks. I could also add the ada_find_main_name()
declaration in another more common .h file, but that would be a dirty
trick, IMO.
--
Joel