Ticket #235: obj.patch
| File obj.patch, 4.8 kB (added by fawzi, 3 years ago) |
|---|
-
a/runtime/internal/dmain2.d
old new 230 230 } 231 231 catch (Exception e) 232 232 { 233 while (e) 234 { 235 if (e.file) 236 { 237 // fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg); 238 console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.toString)("\n"); 239 } 240 else 241 { 242 // fprintf(stderr, "%.*s\n", e.toString()); 243 console (e.classinfo.name)(": ")(e.toString)("\n"); 244 } 245 if (e.info) 246 { 247 console ("----------------\n"); 248 foreach (t; e.info) 249 console (t)("\n"); 250 } 251 if (e.next) 252 console ("\n"); 253 e = e.next; 254 } 233 e.writeOut(delegate void(char[]s){ console(s); }); 255 234 result = EXIT_FAILURE; 256 235 } 257 236 catch (Object o) -
a/runtime/internal/genobj.d
old new 49 49 50 50 extern (C) void onOutOfMemoryError(); 51 51 extern (C) Object _d_allocclass(ClassInfo ci); 52 extern (C) int snprintf(char * s, size_t n, char * format, ...); 52 53 } 53 54 54 55 // NOTE: For some reason, this declaration method doesn't work … … 902 903 // Exception 903 904 //////////////////////////////////////////////////////////////////////////////// 904 905 905 906 906 class Exception : Object 907 907 { 908 struct FrameInfo{ 909 long line; 910 ptrdiff_t offset; 911 size_t address; 912 char[] file; 913 char[] func; 914 char[256] charBuf; 915 void writeOut(void delegate(char[])sink){ 916 char[25] buf; 917 sink(func); 918 auto len=snprintf(buf.ptr,buf.length,"@%zx ",address); 919 assert(len>=0); 920 sink(buf[0..len]); 921 len=snprintf(buf.ptr,buf.length," %+td ",address); 922 assert(len>=0); 923 sink(buf[0..len]); 924 sink(file); 925 len=snprintf(buf.ptr,buf.length,":%ld",line); 926 assert(len>=0); 927 sink(buf[0..len]); 928 } 929 } 908 930 interface TraceInfo 909 931 { 910 int opApply( int delegate( inout char[]) );932 int opApply( int delegate( ref FrameInfo fInfo ) ); 911 933 } 912 934 913 935 char[] msg; … … 916 938 TraceInfo info; 917 939 Exception next; 918 940 919 this( char[] msg, Exception next = null)941 this( char[] msg, char[] file, long line, Exception next, TraceInfo info ) 920 942 { 943 // main constructor, breakpoint this if you want... 921 944 this.msg = msg; 922 945 this.next = next; 923 this.info = traceContext(); 946 this.file = file; 947 this.line = cast(size_t)line; 948 this.info = info; 924 949 } 925 950 926 this( char[] msg, char[] file, size_t line, Exception next =null )951 this( char[] msg, Exception next=null ) 927 952 { 928 this(msg, next); 929 this.file = file; 930 this.line = line; 931 this.info = traceContext(); 953 this(msg,"",0,next,rt_createTraceContext(null)); 954 } 955 956 this( char[] msg, char[] file, long line, Exception next=null ) 957 { 958 this(msg,file,line,next,rt_createTraceContext(null)); 932 959 } 933 960 934 961 char[] toString() 935 962 { 936 963 return msg; 964 } 965 966 void writeOut(void delegate(char[])sink){ 967 if (file) 968 { 969 char[25]buf; 970 sink(this.classinfo.name); 971 sink("@"); 972 sink(file); 973 sink("("); 974 auto len=snprintf(buf.ptr,buf.length,"%ld",line); 975 assert(len>=0); 976 sink(buf[0..len]); 977 sink("): "); 978 sink(toString()); 979 sink("\n"); 980 } 981 else 982 { 983 sink(this.classinfo.name); 984 sink(": "); 985 sink(toString); 986 sink("\n"); 987 } 988 if (info) 989 { 990 sink("----------------\n"); 991 foreach (ref t; info){ 992 t.writeOut(sink); 993 sink("\n"); 994 } 995 } 996 if (next){ 997 sink("\n"); 998 next.writeOut(sink); 999 } 937 1000 } 938 1001 } 939 1002 … … 968 1031 * An object describing the current calling context or null if no handler is 969 1032 * supplied. 970 1033 */ 971 Exception.TraceInfo traceContext( void* ptr = null ) 972 { 1034 extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ){ 973 1035 if( traceHandler is null ) 974 1036 return null; 975 1037 return traceHandler( ptr );

