On Sun, 10 Oct 2010 02:52:06 +0400, Austin Hastings <ah0801...@yahoo.com> wrote:

On 10/8/2010 6:47 PM, Denis Koroskin wrote:
On Sat, 09 Oct 2010 02:36:30 +0400, Austin Hastings <ah0801...@yahoo.com> wrote:

object.Exception: Test
----------------
00 rtdmain2mainrunMain
01 rtdmain2mainrunAll
02 main
03 mainCRTStartup
04 RegisterWaitForInputIdle

Thanks for your help, Benjamin!

My next question would be, why does the stack trace look this way? I'm
throwing the exception from D's main. I assume that's entry #02. But
what are the other two entries, and why are they on the stack?

D main is not the true program entry point, there is a lot of
preparation done (gc_init(), module init, etc) before your main() takes
control, and these entries can be safely stripped since they are usually
not what you are looking for.

Denis,

Sure, there's stuff in assembly that calls main. What I'm asking about is the stuff *inside* main that isn't in my code. As I see it, either:

1. The function I named "main" is at #02 on the above, in which case there are two subroutines that I didn't call on the stack. Then I'd like to know what they are, and whatever else anyone can tell me about them.

2. The function I named "main" is actually "rtdmain2mainrunMain", in which case (a) why was it renamed this horrible value; and (b) what other non-intuitive name manglings (!!) can I expect? (As if there was such a thing as an intuitive name mangling. :-)

3. The function I named "main" is actually "RegisterWaitForInputIdle", which will totally surprise me, in which case please explain why the stack trace is upside down, and why that name was chosen?

=Austin

There is no your main in that stack trace, it looks like it got ignored or something. Try more nested example.

Stack trace is indeed upside-down.

04 I've no idea what RegisterWaitForInputIdle is, just ignore it.
03 mainCRTStartup is any C/C++/D (i.e. any C-based programming language) program entry point. C runtime library gets initialized. 02 main is an "extern (C) int main(int argc, char** argv)", defined in rt\dmain2.d (part of druntime source). This is where any C/C++/D executable starts. In D, this is where Garbage Collector gets initialized, module constructors, unittests ran etc
01 rtdmain2mainrunAll that's just a helper function that is called by main
00 rtdmain2mainrunMain - ditto, a try/catch wrapper around YOUR main
-1 main - this one got lost for some reason

In other words, here is how main looks like in D (slightly simplified):

extern (C) int main(int argc, char** argv) // 02
{
    void runAll() // 01
    {
        gc_init();
        initStaticDataGC();
        _minit();
        _moduleCtor();
        _moduleTlsCtor();
        if (runModuleUnitTests())
            runMain();
        else
            result = EXIT_FAILURE;
        _moduleTlsDtor();
        thread_joinAll();
        _d_isHalting = true;
        _moduleDtor();
        gc_term();
    }


    void runMain() // 00
    {
        result = main(args); // -1
    }

    tryExec(&runAll);

    return result;
}

int main(string[] args); // -1, your main

See http://dsource.org/projects/druntime/browser/trunk/src/rt/dmain2.d#L324 for full source code.

Hope that helps.

Reply via email to