971 – [profile] No profiling output is generated if the application terminates with exit

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 971 - [profile] No profiling output is generated if the application terminates with exit
Summary: [profile] No profiling output is generated if the application terminates with...
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年02月16日 15:36 UTC by David Ferenczi
Modified: 2019年05月23日 08:13 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description David Ferenczi 2007年02月16日 15:36:27 UTC
test1.d :
--------------8<-----------------------------------
int main(char[][] args)
{
 return 0;
}
--------------8<-----------------------------------
test2.d:
--------------8<-----------------------------------
static private import std.c.stdlib: exit;
int main(char[][] args)
{
 exit(0);
 return 0;
}
--------------8<-----------------------------------
dmd test1.d -profile
./test1
--> trace.def and trace.log are generated
dmd test1.d -profile
./test2
--> no output generated
Comment 1 David Ferenczi 2007年02月16日 15:40:53 UTC
In the 2nd case test2.d will be compiled, of course.
dmd test2.d -profile
./test2
> dmd test1.d -profile
> ./test2
> 
> --> no output generated
> 
Comment 2 Sean Kelly 2007年02月16日 15:55:27 UTC
No output will be generated if the application terminates from an 
unhandled exception either. But I think this is correct behavior. If 
the application is terminated abruptly then it should be expected that 
unwinding code will not be executed.
Comment 3 David Ferenczi 2007年02月16日 16:31:05 UTC
It may have been just a bad practice of mine to use the exit function also for normal terminating. The question is, if it's really a misuse, or e.g. exit(EXIT_SUCCESS) should be treated as normal termination.
(Nevertheless I cahnged my code, so it doesn't contain any exit calls.)
Comment 4 Sean Kelly 2007年02月16日 17:55:33 UTC
d-bugmail@puremagic.com wrote:
>
> ------- Comment #3 from david@ferenczi.net 2007年02月16日 16:31 -------
> It may have been just a bad practice of mine to use the exit function also for
> normal terminating. The question is, if it's really a misuse, or e.g. 
> exit(EXIT_SUCCESS) should be treated as normal termination.
That's a good question. A normal termination in C terms is not a normal 
termination in D terms, but one could argue that the D runtime should 
handle this case anyway. I think it would be easy enough to do with 
atexit() however.
Comment 5 Bill Baxter 2007年08月09日 21:43:33 UTC
Ok, so how *does* one exit from deep within a program in a manner that will still generate profile info?
The only thing I could think of was to put an exception handler around the main loop, and then throw an exception when I want to stop execution.
Is that the best option?
Comment 6 Sean Kelly 2007年08月10日 10:58:30 UTC
That's the most straightforward approach. Unfortunately, it only works when done in the main program thread. An alternate, evil approach would be to suspend all threads, manually call the runtime cleanup routines, and then call C exit(). The safest would probably be for the runtime to register its cleanup routines using _atexit() or the equivalent so C exit() can be called.
Comment 7 Walter Bright 2007年08月13日 00:00:07 UTC
You can call trace_term() in internal/trace.d to send out the output. I'll make it extern(C) in the next update to make this easier.
The profiler won't work with multithreaded code anyway.
Comment 8 Justin Spahr-Summers 2009年10月29日 13:12:09 UTC
I don't know if this issue ever got resolved, but now it's cropping up with a "void main" too, even through a clean return. "int main" does not share the problem.
Comment 9 RazvanN 2019年05月23日 08:13:59 UTC
Tested on git HEAD master and trace.def/trace.log are both generated for both files in the original bug report. Closing as WORKSFORME, please reopen if the bug still manifests.


AltStyle によって変換されたページ (->オリジナル) /