mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-01 04:23:14 +01:00
Apply fawzi's patch from #235.
This has some issues which are addressed in my next commit.
This commit is contained in:
@@ -230,28 +230,7 @@ extern (C) int main(int argc, char **argv, char** env)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
while (e)
|
||||
{
|
||||
if (e.file)
|
||||
{
|
||||
// fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg);
|
||||
console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.toString)("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// fprintf(stderr, "%.*s\n", e.toString());
|
||||
console (e.classinfo.name)(": ")(e.toString)("\n");
|
||||
}
|
||||
if (e.info)
|
||||
{
|
||||
console ("----------------\n");
|
||||
foreach (t; e.info)
|
||||
console (t)("\n");
|
||||
}
|
||||
if (e.next)
|
||||
console ("\n");
|
||||
e = e.next;
|
||||
}
|
||||
e.writeOut(delegate void(char[]s){ console(s); });
|
||||
result = EXIT_FAILURE;
|
||||
}
|
||||
catch (Object o)
|
||||
|
||||
@@ -905,9 +905,28 @@ class TypeInfo_Tuple : TypeInfo
|
||||
|
||||
class Exception : Object
|
||||
{
|
||||
struct FrameInfo{
|
||||
long line;
|
||||
ptrdiff_t offset;
|
||||
size_t address;
|
||||
char[] file;
|
||||
char[] func;
|
||||
char[256] charBuf;
|
||||
void writeOut(void delegate(char[])sink){
|
||||
char[25] buf;
|
||||
sink(func);
|
||||
sprintf(buf.ptr,"@%zx ",address);
|
||||
sink(buf[0..strlen(buf.ptr)]);
|
||||
sprintf(buf.ptr," %+td ",address);
|
||||
sink(buf[0..strlen(buf.ptr)]);
|
||||
sink(file);
|
||||
sprintf(buf.ptr,":%ld",line);
|
||||
sink(buf[0..strlen(buf.ptr)]);
|
||||
}
|
||||
}
|
||||
interface TraceInfo
|
||||
{
|
||||
int opApply( int delegate( inout char[] ) );
|
||||
int opApply( int delegate( ref FrameInfo fInfo ) );
|
||||
}
|
||||
|
||||
char[] msg;
|
||||
@@ -916,25 +935,65 @@ class Exception : Object
|
||||
TraceInfo info;
|
||||
Exception next;
|
||||
|
||||
this( char[] msg, Exception next = null )
|
||||
this( char[] msg, char[] file, long line, Exception next, TraceInfo info )
|
||||
{
|
||||
// main constructor, breakpoint this if you want...
|
||||
this.msg = msg;
|
||||
this.next = next;
|
||||
this.info = traceContext();
|
||||
this.file = file;
|
||||
this.line = cast(size_t)line;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
this( char[] msg, char[] file, size_t line, Exception next = null )
|
||||
this( char[] msg, Exception next=null )
|
||||
{
|
||||
this(msg, next);
|
||||
this.file = file;
|
||||
this.line = line;
|
||||
this.info = traceContext();
|
||||
this(msg,"",0,next,rt_createTraceContext(null));
|
||||
}
|
||||
|
||||
this( char[] msg, char[] file, long line, Exception next=null )
|
||||
{
|
||||
this(msg,file,line,next,rt_createTraceContext(null));
|
||||
}
|
||||
|
||||
char[] toString()
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
void writeOut(void delegate(char[])sink){
|
||||
if (file)
|
||||
{
|
||||
char[25]buf;
|
||||
sink(this.classinfo.name);
|
||||
sink("@");
|
||||
sink(file);
|
||||
sink("(");
|
||||
sprintf(buf.ptr,"%ld",line);
|
||||
sink(buf[0..strlen(buf.ptr)]);
|
||||
sink("): ");
|
||||
sink(toString());
|
||||
sink("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sink(this.classinfo.name);
|
||||
sink(": ");
|
||||
sink(toString);
|
||||
sink("\n");
|
||||
}
|
||||
if (info)
|
||||
{
|
||||
sink("----------------\n");
|
||||
foreach (ref t; info){
|
||||
t.writeOut(sink);
|
||||
sink("\n");
|
||||
}
|
||||
}
|
||||
if (next){
|
||||
sink("\n");
|
||||
next.writeOut(sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -968,7 +1027,7 @@ extern (C) void rt_setTraceHandler( TraceHandler h )
|
||||
* An object describing the current calling context or null if no handler is
|
||||
* supplied.
|
||||
*/
|
||||
Exception.TraceInfo traceContext( void* ptr = null )
|
||||
extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ){
|
||||
{
|
||||
if( traceHandler is null )
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user