From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: Re: [RFA/RFC] New command: ``start'' Date: Tue, 18 May 2004 22:27:00 -0000 Message-id: <20040518222740.GZ10684@gnat.com> References: <20040518024700.GV10684@gnat.com> <20040518214712.GD4036@nevyn.them.org> X-SW-Source: 2004-05/msg00551.html > > As briefly discussed on gdb@ and gdb-patches@, here is a first proposal > > for the addition of a new command: ``start''. > > > > I handled the language-dependent issue by adding a new method to the > > language vector. I returns a newly allocated string that tells GDB > > where to insert the breakpoint. I named it "main_program_name" because > > I would expect it to always return the name of a procedure. However, > > it can actually return any location expression. So a language could > > use a different approach and return something like "*0xdeadbeef" or > > "source.c:10" for instance. > > We already have a function for this: main_name. Is it adequate for > Ada? I forgot about this function. But I don't think it's adequate for the start command. If I understand everything correctly, this function relies on some information provided in stabs via N_MAIN symbols. Otherwise, it defaults to "main". This wouldn't necessarily work with any debug format. Also, the purpose of this function is slightly different from what I am trying to achieve with the language method: Despite the fact that most users see Ada programs starting at the begining of their main procedure, a closer approximation is that it starts inside procedure main() too. To give you a better understanding how who it works in Ada (as defined in the Reference Manual [RM for short]), the execution of an Ada program has 3 important phases: 1. Elaboration 2. Program execution 3. Finalization The RM says that the elaboration should be performed inside a procedure called "adainit", and that the finalization should be performed by a procedure called "adafinal". The elaboration and finalization order is computed by a tool called the "binder" that checks all the dependencies, and generate a small source file that looks like this: void adainit (void) { /* Do the program elaboration here. */ } void adafinal (void) { /* Finalize the program. */ } void int main (...) { adainit (); the_user_main_program (); adafinal (); } The last step when building a program is then to call the gnat linker that will do 2 things: compile the file generated by the binder, and then do the link. (this is all automated by our gnatmake tool :). So, even though most Ada users will usually only care about their own main procedure, I occasionally need to go up the stack up to procedure "main" to inspect it. Adapting main_name() to fit the purpose of the start command would cause the backtrace (amount other things) to be a bit shorter, and also depend on the current language. One thing that might be worthwhile, though, is call it from xdefault_main_program_name, instead of hard-coding "main" a second time. But that might introduce an unwanted dependency. -- Joel