[Issue 13406] New: Feature request: @trace attribute for automatic tracing, OR @(scope, scopeFn)
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Aug 30 14:44:41 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13406
Issue ID: 13406
Summary: Feature request: @trace attribute for automatic
tracing, OR @(scope, scopeFn)
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: kevin.lamonte at gmail.com
There have been several proposals for logging in phobos, but I have not seen a
request for tracing. By tracing I mean on-the-fly recording of function
entry+args and exit+return, sent to a logging framework of some kind. Other
languages use aspect-oriented programming (Java) and before/after methods
(lisp) to apply this automatically to all code in a project.
I believe that a @trace function attribute could satisfy this very well.
Desired behavior:
@trace int foo(string bar) {
... blah ...
}
...magically becomes...
int foo(string bar) {
traceFunctionEnter(__LINE__, __FILE__, __MODULE__, __FUNCTION__,
__PRETTYFUNCTION__, [ bar ]);
scope(success) {
traceFunctionExitSuccess(__LINE__, __FILE__, __MODULE__, __FUNCTION__,
__PRETTYFUNCTION__, result);
}
scope(failure) {
traceFunctionExitFailure(__LINE__, __FILE__, __MODULE__, __FUNCTION__,
__PRETTYFUNCTION__, result);
}
... blah ...
}
Add the ability to set traceFunctionEnter / traceFunctionExitFailure /
traceFunctionExitSuccess and a logging framework could automagically plug in
and become a tracing framework too.
If @trace as a feature is too library-specific, this idea could instead be
implemented by something like @(scope, &scopeFn) where scopeFn looks like:
void scopeFn(scopeType, __LINE__, __FILE__, __MODULE__, __FUNCTION__,
__PRETTYFUNCTION__, [ args ])
...where scopeType is an enum value meaning "in", "success", or "failure", and
args contains either the input parameters or the return (value or exception),
respectively.
--
More information about the Digitalmars-d-bugs
mailing list