Changeset 279
- Timestamp:
- 05/24/07 23:06:22 (2 years ago)
- Files:
-
- trunk/ddl/DDLError.d (modified) (1 diff)
- trunk/ddl/DDLReader.d (modified) (10 diffs)
- trunk/ddl/DDLWriter.d (modified) (5 diffs)
- trunk/ddl/Demangle.d (modified) (5 diffs)
- trunk/ddl/DynamicLibrary.d (modified) (3 diffs)
- trunk/ddl/DynamicLibraryLoader.d (modified) (1 diff)
- trunk/ddl/ExportClass.d (modified) (1 diff)
- trunk/ddl/ExportSymbol.d (modified) (1 diff)
- trunk/ddl/FileBuffer.d (modified) (1 diff)
- trunk/ddl/Linker.d (modified) (7 diffs)
- trunk/ddl/LoaderRegistry.d (modified) (8 diffs)
- trunk/ddl/Mangle.d (modified) (1 diff)
- trunk/ddl/PathLibrary.d (modified) (8 diffs)
- trunk/ddl/Utils.d (modified) (4 diffs)
- trunk/ddl/ar/ArchiveLibrary.d (modified) (11 diffs)
- trunk/ddl/ar/ArchiveLoader.d (modified) (2 diffs)
- trunk/ddl/ar/ArchiveReader.d (modified) (4 diffs)
- trunk/ddl/coff/COFFBinary.d (modified) (11 diffs)
- trunk/ddl/coff/COFFImage.d (modified) (19 diffs)
- trunk/ddl/coff/COFFLibrary.d (modified) (2 diffs)
- trunk/ddl/coff/COFFLoader.d (modified) (4 diffs)
- trunk/ddl/coff/COFFModule.d (modified) (3 diffs)
- trunk/ddl/coff/COFFObject.d (modified) (10 diffs)
- trunk/ddl/coff/COFFWrite.d (modified) (2 diffs)
- trunk/ddl/coff/DebugSymbol.d (modified) (15 diffs)
- trunk/ddl/coff/cursor.d (modified) (5 diffs)
- trunk/ddl/ddl/DDLBinary.d (modified) (7 diffs)
- trunk/ddl/ddl/DDLLibrary.d (modified) (3 diffs)
- trunk/ddl/ddl/DDLLoader.d (modified) (2 diffs)
- trunk/ddl/elf/ELFBinary.d (modified) (2 diffs)
- trunk/ddl/elf/ELFLibrary.d (modified) (5 diffs)
- trunk/ddl/elf/ELFModule.d (modified) (1 diff)
- trunk/ddl/elf/ELFObjLoader.d (modified) (3 diffs)
- trunk/ddl/elf/ELFReader.d (modified) (2 diffs)
- trunk/ddl/insitu/InSituLibBinary.d (modified) (6 diffs)
- trunk/ddl/insitu/InSituLibrary.d (modified) (1 diff)
- trunk/ddl/insitu/InSituLoader.d (modified) (3 diffs)
- trunk/ddl/insitu/InSituMapBinary.d (modified) (9 diffs)
- trunk/ddl/insitu/InSituModule.d (modified) (2 diffs)
- trunk/ddl/omf/OMFBinary.d (modified) (12 diffs)
- trunk/ddl/omf/OMFLibrary.d (modified) (6 diffs)
- trunk/ddl/omf/OMFLoader.d (modified) (3 diffs)
- trunk/ddl/omf/OMFModule.d (modified) (3 diffs)
- trunk/ddl/omf/OMFReader.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ddl/DDLError.d
r143 r279 34 34 un-recoverable. 35 35 */ 36 class DDLError : Error{ 36 class DDLError{ 37 char[] message; 37 38 public this(char[] message){ 38 super(39 this.message = 39 40 "[Error] You have run into a condition not handled, or possibly incorrectly handled, by DDL.\n" ~ 40 41 message ~ 41 42 "\nPlease create a ticket (or look for similar ones) at http://trac.dsource.org/projects/ddl/newticket, explain the circumstances and paste this message into it. Also, if possible, please attach a minimal, reproducible testcase.\n - Thank You. -" 42 ); 43 ; 44 } 45 46 public char[] toUtf8(){ 47 return message; 43 48 } 44 49 } trunk/ddl/DDLReader.d
r271 r279 24 24 +/ 25 25 /** 26 Provides Mango binary Reader support, with a few enhancements26 Provides Tango binary Reader support, with a few enhancements 27 27 28 28 Authors: Eric Anderton … … 33 33 34 34 private import ddl.Utils; 35 36 private import mango.io.Reader; 37 private import mango.io.Buffer; 38 private import mango.io.model.IBuffer; 39 private import mango.io.model.IConduit; 40 41 debug private import mango.io.Stdout; 35 private import ddl.FileBuffer; 36 37 enum Anchor{ 38 None, 39 Begin, 40 End, 41 Current 42 } 42 43 43 44 /** 44 Mango IO Reader subclass.45 Tango IO Reader subclass. 45 46 46 47 DDLReader provides a few key pieces of functionality that are used heavily within … … 53 54 to subclass the reader, as to create a richer and more task-oriented feature set. 54 55 */ 55 public class DDLReader : Reader{ 56 /** 57 Simple constructor. Requires no IBuffer or IConduit instances. 56 public class DDLReader{ 57 ubyte[] data; 58 size_t position; 59 60 /** 61 Simple constructor. 58 62 59 63 Params: … … 61 65 */ 62 66 public this(void[] data){ 63 super(new Buffer(data,data.length)); 64 } 65 66 /** 67 IBuffer style constructor. 68 69 Params: 70 buffer = buffer to read 71 */ 72 public this (IBuffer buffer){ 73 super(buffer); 74 } 75 76 /** 77 IConduit style constructor. 78 79 Params: 80 conduit = conduit to read 81 */ 82 public this (IConduit conduit){ 83 super(conduit); 84 } 67 this.data = cast(ubyte[])data; 68 } 69 70 public this(FileBuffer buffer){ 71 this.data = buffer.data; 72 } 85 73 86 74 /** … … 92 80 */ 93 81 public DDLReader peek(inout ubyte x){ 94 x = (cast(ubyte[])buffer.get(1,false))[0]; 82 assert(this.hasMore()); 83 x = data[position]; 95 84 return this; 96 85 } … … 104 93 elements = (default: uint.max) the number of bytes to peek. 105 94 */ 106 public DDLReader peek(inout ubyte[] x, uint elements = uint.max){107 if(elements == uint.max)108 elements = buffer.readable;109 110 assert(elements <= buffer.readable); 111 112 x = (cast(ubyte[])buffer.get(elements,false)); 95 public DDLReader peek(inout ubyte[] x,size_t elements = size_t.max){ 96 if(elements == size_t.max){ 97 x = data[position..$]; 98 } 99 else{ 100 x = data[position..position+elements]; 101 } 113 102 return this; 114 103 } … … 122 111 x = (inout) will contain everything from the current read position to the end of the file. 123 112 */ 124 DDLReader getAll(inout void[] x)113 public DDLReader getAll(inout void[] x) 125 114 { 126 //props to Kris for suggesting this method of getting 100% of the remaining data in a conduit 127 IConduit conduit = getBuffer.getConduit(); 128 129 x = getBuffer.get(getBuffer.readable); //exhaust the buffer 130 131 if(conduit){ 132 static const uint BUFFER_LEN = 8192; 133 void[] content = new void[BUFFER_LEN]; 134 uint filled = 0; 115 x = data[position..$]; 116 position = data.length; 117 return this; 118 } 119 120 public DDLReader _get(T)(inout T x) 121 { 122 //debug debugLog("reading element size: {0}",T.sizeof); 123 x = *(cast(T*)(data[position..position + T.sizeof].ptr)); 124 position += T.sizeof; 125 return this; 126 } 127 128 alias _get!(char) get; 129 alias _get!(wchar) get; 130 alias _get!(dchar) get; 131 alias _get!(byte) get; 132 alias _get!(ubyte) get; 133 alias _get!(short) get; 134 alias _get!(ushort) get; 135 alias _get!(int) get; 136 alias _get!(uint) get; 137 alias _get!(long) get; 138 alias _get!(ulong) get; 139 140 public DDLReader _getArray(T)(inout T[] x,size_t elements = size_t.max) 141 { 142 size_t end; 143 if(elements == size_t.max){ 144 //debug debugLog("reading max"); 145 end = data.length - (data.length % T.sizeof); 146 x = cast(T[])(data[position..end]); 147 } 148 else{ 149 //debug debugLog("size: {3} elements: {0} len: {1} pos: {2}",elements,data.length,position,T.sizeof); 150 end = position + (elements * T.sizeof); 151 x = cast(T[])(data[position..end]); 152 } 153 position = end; 154 return this; 155 } 156 157 alias _getArray!(char) get; 158 alias _getArray!(wchar) get; 159 alias _getArray!(dchar) get; 160 alias _getArray!(byte) get; 161 alias _getArray!(ubyte) get; 162 alias _getArray!(short) get; 163 alias _getArray!(ushort) get; 164 alias _getArray!(int) get; 165 alias _getArray!(uint) get; 166 alias _getArray!(long) get; 167 alias _getArray!(ulong) get; 135 168 136 while(true){137 uint chunk = conduit.read(content[filled..$]);138 if (chunk is conduit.Eof)139 break;140 filled += chunk;141 if (content.length - filled < 1024)142 content.length = content.length + BUFFER_LEN;143 }144 if(filled > 0){145 x ~= content [0..filled]; // add on additional data146 }147 }148 149 return this;150 }151 152 169 /** 153 170 Returns: (true/false) If the conduit has any more data to be read. 154 171 */ 155 172 bool hasMore(){ 156 157 //TODO: instead of try-catch, check for underflow instead 158 try{ 159 void[] result = getBuffer().get(1,false); 160 return result != null; 161 } 162 catch(Exception e){ 163 return false; 164 } 173 return position < data.length; 165 174 } 166 175 … … 168 177 Perform a seek relative to the current buffer position and status using the conduit. 169 178 170 Some Mango conduits are seekable directly. For all others, this method seeks by179 Some Tango conduits are seekable directly. For all others, this method seeks by 171 180 manipulating the buffer and the current read position instead. 172 181 … … 179 188 calculated (see: ISeekable.SeekAnchor for more info). 180 189 */ 181 void seek(ulong offset, ISeekable.SeekAnchor anchor=ISeekable.SeekAnchor.Begin){ 182 IConduit conduit = getBuffer.getConduit(); 183 184 if(conduit){ 185 ISeekable seekableConduit = cast(ISeekable)(conduit); 186 assert(seekableConduit); 187 188 // seek and wipe out the buffer 189 switch(anchor){ 190 case ISeekable.SeekAnchor.Begin: 191 case ISeekable.SeekAnchor.End: 192 seekableConduit.seek(offset,anchor); 193 break; 194 case ISeekable.SeekAnchor.Current: 195 seekableConduit.seek(offset - getBuffer.readable,anchor); 196 break; 197 } 198 getBuffer.clear(); 190 DDLReader seek(ulong offset, Anchor anchor = Anchor.Begin){ 191 switch(anchor){ 192 case Anchor.Begin: 193 assert(offset < data.length); 194 position = offset; 195 break; 196 case Anchor.End: 197 assert(position + offset < data.length); 198 position = data.length + offset; 199 break; 200 default: 201 case Anchor.None: 202 case Anchor.Current: 203 assert(position + offset < data.length); 204 position += offset; 205 break; 199 206 } 200 else{ // no conduit for buffer 201 switch(anchor){ 202 case ISeekable.SeekAnchor.Begin: 203 getBuffer.skip(offset-getBuffer.getPosition); 204 break; 205 case ISeekable.SeekAnchor.End: 206 getBuffer.skip(getBuffer.readable-offset); 207 break; 208 case ISeekable.SeekAnchor.Current: 209 getBuffer.skip(offset); 210 break; 211 } 212 } 207 return this; 213 208 } 214 209 … … 216 211 Returns: The position relative to the current buffer position. 217 212 */ 218 ulong getPosition(){ 219 IConduit conduit = getBuffer.getConduit(); 220 if(conduit){ 221 ISeekable seekableConduit = cast(ISeekable)(conduit); 222 assert(seekableConduit); 223 return seekableConduit.getPosition() - getBuffer.readable; 224 } 225 else{ 226 return(getBuffer.getPosition); 227 } 228 } 229 230 // override to provide debug support 231 debug override protected uint read (void *dst, uint bytes, uint type){ 232 try{ 233 return super.read(dst,bytes,type); 234 } 235 catch(Exception e){ 236 Stdout.println("Exception thrown while reading (%0.8X) %d bytes, type %d",dst,bytes,type); 237 throw e; 238 } 239 return 0; 213 size_t getPosition(){ 214 return position; 215 } 216 217 ubyte[] getData(){ 218 return data; 240 219 } 241 220 } trunk/ddl/DDLWriter.d
r271 r279 24 24 +/ 25 25 /** 26 Provides Mango binary Writer support, with a few enhancements26 Provides Tango binary Writer support, with a few enhancements 27 27 28 28 Authors: Eric Anderton … … 32 32 module ddl.DDLWriter; 33 33 34 private import mango.io.Writer; 35 private import mango.io.model.IBuffer; 36 private import mango.io.model.IConduit; 34 private import ddl.Utils; 35 private import ddl.FileBuffer; 36 37 enum Anchor{ 38 None, 39 Begin, 40 End, 41 Current 42 } 37 43 38 44 /** 39 Mango IO Writer subclass.45 Tango IO Writer subclass. 40 46 41 47 DDLWriter, apart from adding symmetry to DDLReader, provides seeking capability for 42 48 random-access <i>output</i>. 43 49 */ 44 public class DDLWriter : Writer{ 50 public class DDLWriter{ 51 ubyte[] data; 52 uint position; 53 45 54 /** 46 55 IBuffer style constructor. … … 49 58 buffer = buffer to read 50 59 */ 51 public this ( IBuffer buffer){52 super(buffer);60 public this (){ 61 position = 0; 53 62 } 54 63 55 /** 56 IConduit style constructor. 57 58 Params: 59 conduit = conduit to read 60 */ 61 public this (IConduit conduit){ 62 super(conduit); 64 public this (ubyte[] data){ 65 this.data = data; 66 position = data.length; 67 } 68 69 public this(FileBuffer buffer){ 70 this.data = buffer.data; 71 position = 0; 72 } 73 74 DDLWriter putAll(void[] x){ 75 ubyte[] newData = cast(ubyte[])x; 76 if(position == data.length){ 77 data ~= newData; 78 position = data.length; 79 } 80 else{ 81 data[position..position+newData.length] = newData; 82 } 83 return this; 63 84 } 64 85 65 86 DDLWriter put(T)(T x){ 87 ubyte[] newData = (cast(ubyte*)(cast(void*)&x))[0..T.sizeof]; 88 if(position == data.length){ 89 data ~= newData; 90 position = data.length; 91 } 92 else{ 93 data[position..position+newData.length] = newData; 94 position += newData.length; 95 } 96 return this; 97 } 98 66 99 /** 67 100 Perform a seek relative to the current buffer position and status using the conduit. 68 101 69 Some Mango conduits are seekable directly. For all others, this method seeks by102 Some Tango conduits are seekable directly. For all others, this method seeks by 70 103 manipulating the buffer and the current read position instead. 71 104 … … 78 111 calculated (see: ISeekable.SeekAnchor for more info). 79 112 */ 80 void seek(ulong offset, ISeekable.SeekAnchor anchor=ISeekable.SeekAnchor.Begin){ 81 IConduit conduit = getBuffer.getConduit(); 82 83 if(conduit){ 84 ISeekable seekableConduit = cast(ISeekable)(conduit); 85 assert(seekableConduit); 86 87 // seek and wipe out the buffer 88 ulong writable = getBuffer.readable; 89 getBuffer.flush(); 90 91 switch(anchor){ 92 case ISeekable.SeekAnchor.Begin: 93 case ISeekable.SeekAnchor.End: 94 seekableConduit.seek(offset,anchor); 95 break; 96 case ISeekable.SeekAnchor.Current: 97 seekableConduit.seek(offset - writable,anchor); 98 break; 99 } 113 DDLWriter seek(ulong offset, Anchor anchor = Anchor.Begin){ 114 switch(anchor){ 115 case Anchor.Begin: 116 assert(offset < data.length); 117 position = offset; 118 break; 119 case Anchor.End: 120 assert(data.length + offset < data.length); 121 position = data.length + offset; 122 break; 123 default: 124 case Anchor.None: 125 case Anchor.Current: 126 assert(position + offset < data.length); 127 position += offset; 128 break; 100 129 } 101 else{ // no conduit for buffer 102 switch(anchor){ 103 case ISeekable.SeekAnchor.Begin: 104 getBuffer.skip(offset-getBuffer.getPosition); 105 break; 106 case ISeekable.SeekAnchor.End: 107 getBuffer.skip(getBuffer.readable-offset); 108 break; 109 case ISeekable.SeekAnchor.Current: 110 getBuffer.skip(offset); 111 break; 112 } 113 } 130 return this; 114 131 } 115 132 … … 117 134 Returns: The position relative to the current buffer position. 118 135 */ 119 ulong getPosition(){ 120 IConduit conduit = getBuffer.getConduit(); 121 if(conduit){ 122 ISeekable seekableConduit = cast(ISeekable)(conduit); 123 assert(seekableConduit); 124 return seekableConduit.getPosition() + getBuffer.readable; 125 } 126 else{ 127 return(getBuffer.getPosition); 128 } 129 } 136 size_t getPosition(){ 137 return position; 138 } 139 140 ubyte[] getData(){ 141 return data; 142 } 130 143 } trunk/ddl/Demangle.d
r271 r279 33 33 module ddl.Demangle; 34 34 35 private import std.demangle;35 private import etc.demangle; 36 36 37 37 debug private import ddl.Utils; … … 46 46 PublicSymbol, 47 47 PublicDSymbol, 48 ClassDefinition, 49 Initalizer, 50 Vtable, 51 VarArguments, 52 PlatformHook, 53 DAssert, 54 DArray, 55 ModuleCtor, 56 ModuleDtor, 57 ModuleInfo, 58 Main, 59 WinMain, 60 Nullext 48 ModuleInfo 61 49 } 62 50 … … 72 60 */ 73 61 public char[] demangleSymbol(char[] symbol){ 74 return std.demangle.demangle(symbol);62 return demangle(symbol); 75 63 } 76 64 77 65 bool startsWith(char[] value,char[] test){ 78 66 return value.length >= test.length && value[0..test.length] == test; 67 } 68 69 bool endsWith(char[] value,char[] test){ 70 return value.length >= test.length && value[$-test.length .. $] == test; 79 71 } 80 72 … … 89 81 */ 90 82 public DemangleType getDemangleType(char[] symbol){ 91 if(symbol.startsWith("_Class")){ 92 return DemangleType.ClassDefinition; 93 } 94 else if(symbol.startsWith("__init_")){ 95 return DemangleType.Initalizer; 96 } 97 else if(symbol.startsWith("__vtbl_")){ 98 return DemangleType.Vtable; 99 } 100 else if(symbol.startsWith("__arguments_")){ 101 return DemangleType.VarArguments; 102 } 103 else if(symbol.startsWith("__d")){ 104 return DemangleType.PlatformHook; 105 } 106 else if(symbol.startsWith("_assert_")){ 107 return DemangleType.DAssert; 108 } 109 else if(symbol.startsWith("_array_")){ 110 return DemangleType.DArray; 111 } 112 else if(symbol.startsWith("__modctor_")){ 113 return DemangleType.ModuleCtor; 114 } 115 else if(symbol.startsWith("__moddtor_")){ 116 return DemangleType.ModuleDtor; 117 } 118 else if(symbol.startsWith("__ModuleInfo_")){ 83 if (symbol.endsWith("__ModuleInfoZ")) { 119 84 return DemangleType.ModuleInfo; 120 85 } 121 else if(symbol.startsWith("__nullext")){122 return DemangleType.Nullext;123 }124 else if(symbol.startsWith("_Dmain")){125 return DemangleType.Main;126 }127 else if(symbol.startsWith("_DWinMain")){128 return DemangleType.WinMain;129 }130 86 else if(symbol.startsWith("_D")){ 131 87 return DemangleType.PublicDSymbol; … … 179 135 return result; 180 136 } 137 trunk/ddl/DynamicLibrary.d
r271 r279 146 146 template getClassInfo(char[] classname){ 147 147 ClassInfo getClassInfo(){ 148 return cast(ClassInfo)getSymbol("_ _Class_" ~ mangleSymbolName!(classname)).address;148 return cast(ClassInfo)getSymbol("_D" ~ mangleSymbolName!(classname) ~ "7__ClassZ").address; 149 149 } 150 150 } … … 240 240 foreach (mod; getModules) { 241 241 foreach (sym; mod.getSymbols) { 242 const char[] prefix = `__Class_`;242 const char[] suffix = `7__ClassZ`; 243 243 244 if (sym.name.length > prefix.length && sym.name[0 .. prefix.length] == prefix) {244 if (sym.name.length > suffix.length && sym.name[$-suffix.length .. $] == suffix) { 245 245 ClassInfo ci = cast(ClassInfo)getSymbol(sym.name).address; 246 246 assert (ci !is null); … … 248 248 uint dummy; 249 249 if (T.classinfo !is ci && _d_isbaseof2(ci, T.classinfo, dummy)) { 250 res ~= new ExportClass!(T)(ci, sym.name[ prefix.length ..length], this);250 res ~= new ExportClass!(T)(ci, sym.name[0 .. $-suffix.length], this); 251 251 } 252 252 } trunk/ddl/DynamicLibraryLoader.d
r195 r279 53 53 Returns: true if the file can be loaded by this loader, false if it cannot. 54 54 */ 55 public b itcanLoadLibrary(FileBuffer file);55 public bool canLoadLibrary(FileBuffer file); 56 56 57 57 /** trunk/ddl/ExportClass.d
r271 r279 30 30 import ddl.DDLException; 31 31 32 import std.regexp : RegExp;32 import tango.text.Regex; 33 33 34 34 /** trunk/ddl/ExportSymbol.d
r272 r279 78 78 */ 79 79 public char[] name; 80 80 81 /** 82 Line number of the symbol in the original sourcecode, or zero if debug information is not 83 available in the parent module. 84 */ 85 public ushort lineNumber; 86 81 87 /** 82 88 Returns the resolution status of this symbol. trunk/ddl/FileBuffer.d
r271 r279 25 25 module ddl.FileBuffer; 26 26 27 private import mango.io.Buffer;28 private import mango.io.FileConduit;27 private import tango.io.File; 28 private import tango.io.FileConduit; 29 29 30 private import mango.io.model.IBuffer; 31 private import mango.io.model.IConduit; 32 33 /** 34 Gives the basic Mango buffer class some additional information about its origin. 35 */ 36 //TODO: should this pre-buffer the entire file into memory first? 37 class FileBuffer: Buffer{ 30 struct FileBuffer{ 38 31 FilePath path; 39 40 public this(char[] path, FileStyle.Bits style = FileStyle.ReadExisting){ 41 this.path = new FilePath(path); 42 super(new FileConduit(this.path,style)); 32 ubyte[] data; 33 34 static FileBuffer opCall(char[] path){ 35 FileBuffer _this; 36 _this.path = new FilePath(path); 37 _this.data = cast(ubyte[])(new File(_this.path)).read; 38 return _this; 43 39 } 44 40 45 public this(FilePath path, FileStyle.Bits style = FileStyle.ReadExisting){ 46 super(new FileConduit(path,style)); 47 this.path = path; 41 static FileBuffer opCall(FilePath path){ 42 FileBuffer _this; 43 _this.path = new FilePath(path.toUtf8); 44 _this.data = cast(ubyte[])(new File(_this.path)).read; 45 return _this; 48 46 } 49 47 50 public this(FilePath path,void[] data){ 51 super(data,data.length); 52 this.path = path; 48 static FileBuffer opCall(char[] path,ubyte[] data){ 49 FileBuffer _this; 50 _this.path = new FilePath(path); 51 _this.data = data; 52 return _this; 53 } 54 55 static FileBuffer opCall(FilePath path,ubyte[] data){ 56 FileBuffer _this; 57 _this.path = new FilePath(path.toUtf8); 58 _this.data = data; 59 return _this; 53 60 } 54 61 55 public this(char[] path,void[] data){ 56 super(data,data.length); 57 this.path = new FilePath(path); 58 } 59 60 public this(IConduit conduit,FilePath path){ 61 super(conduit); 62 this.path = path; 63 } 64 65 public this(FileConduit file){ 66 super(file); 67 this.path = file.getPath; 68 } 69 70 public FilePath getPath(){ 62 FilePath getPath(){ 71 63 return path; 72 64 } 73 65 74 public IBuffer.Style getStyle(){ 75 return IBuffer.Mixed; 76 } 77 78 public void close(){ 79 this.flush(); 80 this.getConduit().close(); 66 void save(){ 67 (new File(this.path)).write(this.data); 81 68 } 82 69 } trunk/ddl/Linker.d
r273 r279 1 1 /+ 2 Copyright (c) 2005-200 6Eric Anderton, Tomasz Stachowiak2 Copyright (c) 2005-2007 Eric Anderton, Tomasz Stachowiak 3 3 4 4 Permission is hereby granted, free of charge, to any person … … 37 37 private import ddl.DDLException; 38 38 39 private import std.moduleinit; // used for ModuleInfo type40 41 39 debug private import ddl.Utils; 42 40 41 42 43 // for the phobos backtrace hack 44 version(Stacktrace){ 45 extern(C) extern void regist_cb(char* name, void* fp); 46 extern(C) extern void addDebugLineInfo__(uint addr, ushort line, char* file); 47 } 43 48 /** 44 49 Exception class used exclusively by the Linker. … … 63 68 */ 64 69 public this(DynamicModule reason){ 65 super("LinkModuleException: cannot resolve '" ~ reason.getName ~ "'\n" ~ reason.toString()); 70 super("LinkModuleException: cannot resolve '" ~ reason.getName ~ "'\n" ~ reason.toUtf8()); 71 this.mod = reason; 72 } 73 } 74 75 class ModuleCtorError : Exception{ 76 ModuleInfo mod; 77 78 /** 79 Module that prompted the link exception. 80 */ 81 ModuleInfo reason(){ 82 return this.mod; 83 } 84 85 /** 86 Constructor. 87 88 Params: 89 reason = the module that prompts the exception 90 */ 91 public this(ModuleInfo reason){ 92 super("ModuleCtorError: cannot init '" ~ reason.name ~ "'\n"); 66 93 this.mod = reason; 67 94 } … … 119 146 if (m.flags & MIctordone) return; 120 147 121 debug debugLog("this module: %0.8X",cast(void*)m);122 debug debugLog("(name: %0.8X%d)",m.name.ptr,m.name.length);123 debug debugLog("(ctor: %0.8X)",cast(void*)(m.ctor));124 debug debugLog("(dtor: %0.8X)",cast(void*)(m.dtor));125 debug debugLog("Module: %s\n",m.name);148 debug debugLog("this module: {0:X8}",cast(void*)m); 149 debug debugLog("(name: {0:X8} %d)",m.name.ptr,m.name.length); 150 debug debugLog("(ctor: {0:X8})",cast(void*)(m.ctor)); 151 debug debugLog("(dtor: {0:X8})",cast(void*)(m.dtor)); 152 debug debugLog("Module: {0}\n",m.name); 126 153 127 154 if (m.ctor || m.dtor) … … 130 157 { if (skip) 131 158 return; 132 throw new ModuleCtorError(m);159 throw new ModuleCtorError(m); 133 160 } 134 161 135 162 m.flags |= MIctorstart; 136 debug debugLog("running imported modules ( %d)...",m.importedModules.length);163 debug debugLog("running imported modules ({0})...",m.importedModules.length); 137 164 foreach(ModuleInfo imported; m.importedModules){ 138 debug debugLog("running: [ %0.8X]",cast(void*)imported);165 debug debugLog("running: [{0:X8}]",cast(void*)imported); 139 166 initModule(imported,0); 140 167 debug debugLog("-done."); 141 168 } 142 debug debugLog("running ctor [ %0.8X]",cast(void*)m.ctor);169 debug debugLog("running ctor [{0:X8}]",cast(void*)m.ctor); 143 170 if (m.ctor) 144 171 (*m.ctor)(); … … 152 179 { 153 180 m.flags |= MIctordone; 154 debug debugLog("running imported modules ( %d)...",m.importedModules.length);181 debug debugLog("running imported modules ({0})...",m.importedModules.length); 155 182 foreach(ModuleInfo imported; m.importedModules){ 156 debug debugLog("running: [ %0.8X]",cast(void*)imported);183 debug debugLog("running: [{0:X8}]",cast(void*)imported); 157 184 initModule(imported,1); 158 185 debug debugLog("-done."); … … 237 264 auto allSymbols = mod.getSymbols(); 238 265 foreach (symbol; allSymbols) { 266 version(Stacktrace){ 267 if (symbol.address !is null) { 268 //printf("symbol %.*s line: %d\n", symbol.name, symbol.lineNumber); 269 regist_cb((symbol.name ~ \0).ptr, symbol.address); 270 addDebugLineInfo__(cast(uint)symbol.address, symbol.lineNumber, mod.getName); 271 } 272 } 273 239 274 // symbol must be defined and be local only 240 275 if (symbol.address is null || symbol.isExternal) continue; 241 if (symbol.name.length > `__ModuleInfo_`.length && symbol.name[0 .. `__ModuleInfo_`.length] == `__ModuleInfo_`) { 276 char[] suffix = `__ModuleInfoZ`; 277 if (symbol.name.length > suffix.length && symbol.name[$ - suffix.length .. $] == suffix) { 242 278 debug debugLog("Found moduleinfo for %s at [%0.8X] %s",mod.getName,symbol.address,symbol.name); 243 279 moduleSet[symbol.name] = cast(ModuleInfo)(symbol.address); trunk/ddl/LoaderRegistry.d
r261 r279 1 1 /+ 2 Copyright (c) 2005-200 6Eric Anderton2 Copyright (c) 2005-2007 Eric Anderton 3 3 4 4 Permission is hereby granted, free of charge, to any person … … 29 29 private import ddl.FileBuffer; 30 30 31 debug private import mango.io.Stdout;31 debug private import tango.io.Stdout; 32 32 33 33 debug private import ddl.Utils; … … 144 144 DynamicLibrary lib; 145 145 foreach(DynamicLibraryLoader loader;loaders){ 146 debug debugLog("LoaderRegistry.load: trying %sloader",loader.getLibraryType);146 debug debugLog("LoaderRegistry.load: trying {0} loader",loader.getLibraryType); 147 147 if(loader.canLoadLibrary(buffer)){ 148 148 lib = loader.load(this,buffer); … … 153 153 delete lib; // force collection on 'result' 154 154 lib = null; 155 throw new LibraryVersionException(buffer.getPath.to String(),attrStdVersion,*libraryStdVersion);155 throw new LibraryVersionException(buffer.getPath.toUtf8(),attrStdVersion,*libraryStdVersion); 156 156 } 157 157 } … … 178 178 */ 179 179 public DynamicLibrary load(char[] filename,char[] attrStdVersion = ""){ 180 return load( newFileBuffer(filename),attrStdVersion);180 return load(FileBuffer(filename),attrStdVersion); 181 181 } 182 182 … … 186 186 file = the file to test. The file is expected to already be loaded. 187 187 */ 188 public b itcanLoad(FileBuffer file){188 public bool canLoad(FileBuffer file){ 189 189 foreach(DynamicLibraryLoader loader;loaders){ 190 190 if(loader.canLoadLibrary(file)){ … … 200 200 filename = name of the file to test. 201 201 */ 202 public b itcanLoad(char[] filename){
