Changeset 223

Show
Ignore:
Timestamp:
08/01/06 23:42:41 (2 years ago)
Author:
pragma
Message:

Working PathLibrary? implementation, complete with two test cases.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ddl/PathLibrary.d

    r176 r223  
    3333private import ddl.Attributes; 
    3434private import ddl.ExportSymbol; 
     35private import ddl.Utils; 
    3536 
    3637private import mango.io.FileScan; 
     
    4950    FilePath root; 
    5051     
     52    debug protected void debugPathList(char[] prompt,FilePath[] list){ 
     53        debugLog("%s (%d)\n",prompt,list.length); 
     54        foreach(path; list){ 
     55            debugLog("  %s\n",path.toUtf8()); 
     56        }        
     57    } 
     58     
    5159    protected FilePath[] getRootFiles(){ 
    5260        FilePath[] result = (new FileProxy(root)).toList(); 
     
    5765            result.length = 0; 
    5866        } 
    59         debugLog("PathLibrary.getRootFiles - %s",result); 
     67        debug debugPathList("PathLibrary.getRootFiles",result); 
    6068        return result; 
    6169    } 
     
    6977            result.length = 0; 
    7078        } 
    71         debugLog("PathLibrary.getRootFiles - %s",result); 
     79        debug debugPathList("PathLibrary.getFiles",result); 
    7280        return result; 
    7381    } 
     
    8795        scan.files(&handle); 
    8896         
    89         debugLog("PathLibrary.getFiles - %s",result); 
     97        debug debugPathList("PathLibrary.getAllFiles",result); 
    9098        return result; 
    9199    } 
     
    105113    } 
    106114     
     115    protected char[] parseNamespace(char[] symbolName){ 
     116        char[] dName = demangleSymbol(symbolName); 
     117        uint split; 
     118         
     119        // find where symbol ends 
     120        for(split=0; split<dName.length; split++){ 
     121            switch(dName[split]){ 
     122            case '(': 
     123            case ' ': 
     124            case ';': 
     125                break; 
     126            default: 
     127            } 
     128        } 
     129        return dName[0..split]; 
     130    } 
     131     
    107132    public this(char[] rootPath,LoaderRegistry loaderRegistry){ 
    108133        this.root = new FilePath(rootPath); 
     
    111136        //pre-load all root libs 
    112137        foreach(FilePath filepath; getRootFiles()){ 
    113             debugLog("[PathLibrary] Loading: %s",filepath.splice(root)); 
     138            debug debugLog("[PathLibrary] Loading: %s",filepath.splice(root)); 
    114139            DynamicLibrary lib = loaderRegistry.load(filepath.splice(root)); 
    115140            if(lib){ 
     
    118143        } 
    119144         
    120         attributes["PATH.path"] = root.toString
    121     } 
    122      
    123     public ExportSymbol getExport(char[] name){ 
    124         DynamicModule mod = getModuleForExport(name); 
    125         if(mod) return mod.getExport(name); 
    126         return ExportSymbol.NONE
    127     } 
    128      
    129     public ExportSymbol[] getExports(){ 
     145        attributes["PATH.path"] = root.toUtf8
     146    } 
     147     
     148    public ExportSymbolPtr getSymbol(char[] name){ 
     149        DynamicModule mod = this.getModuleForSymbol(name); 
     150        if(mod) return mod.getSymbol(name); 
     151        return null
     152    } 
     153     
     154    public ExportSymbol[] getSymbols(){ 
    130155        ExportSymbol[] symbols; 
    131156        foreach(DynamicModule mod; getModules()){ 
    132             symbols ~= mod.getExports(); 
     157            symbols ~= mod.getSymbols(); 
    133158        } 
    134159        return symbols; 
     
    155180    } 
    156181 
    157     public DynamicModule getModuleForExport(char[] name){ 
     182    public DynamicModule getModuleForSymbol(char[] name){ 
    158183        if(name.length > 2 && name[0..2] == "_D"){ 
    159184            char[] namespace = parseNamespace(name); 
     
    161186            // dig through the root libs     
    162187            foreach(DynamicLibrary lib; rootLibraries){ 
    163                 DynamicModule mod = lib.getModuleForExport(name); 
     188                DynamicModule mod = lib.getModuleForSymbol(name); 
    164189                cachedLibraries[namespace] = lib; 
    165190                if(mod) return mod; 
     
    168193            // attempt to search the cache 
    169194            DynamicLibrary* pLib = namespace in cachedLibraries; 
    170             if(pLib) return pLib.getModuleForExport(name); 
     195            if(pLib) return pLib.getModuleForSymbol(name); 
    171196             
    172197            // look for a path match 
     
    176201                foreach(FilePath libPath; getFiles(path)){ 
    177202                    DynamicLibrary lib = loaderRegistry.load(libPath.toString); 
    178                     if(lib) return lib.getModuleForExport(name); 
     203                    if(lib) return lib.getModuleForSymbol(name); 
    179204                } 
    180205            } 
     
    184209            // dig through the root libs 
    185210            foreach(DynamicLibrary lib; rootLibraries){ 
    186                 DynamicModule mod = lib.getModuleForExport(name); 
     211                DynamicModule mod = lib.getModuleForSymbol(name); 
    187212                if(mod) return mod; 
    188213            }    
    189214        } 
    190215        //failed to find the module 
     216        debugLog("PathLibrary.getModuleForSymbol - failed to find: %s",name); 
    191217        return null; 
    192218    } 
  • trunk/ddl/omf/OMFLibrary.d

    r219 r223  
    8181         
    8282    public DynamicModule getModuleForSymbol(char[] name){ 
    83         debug debugLog("[OMF] looking for " ~ name); 
     83        debug debugLog("[OMF] looking for %s in %s",name,attributes["omf.filename"]); 
    8484        DynamicModule* mod = name in crossReference; 
    8585        debug debugLog("[OMF] Result: %0.8X",mod); 
  • trunk/ddl/omf/OMFModule.d

    r221 r223  
    271271                symbolXref[binary.names[comdat.nameIndex]].type = SymbolType.Strong; 
    272272                symbolXref[binary.names[comdat.nameIndex]].address = *addr; 
    273                  
    274                 debug debugLog("%d %s first bytes: %0.8X\n",idx,cast(char[])binary.names[comdat.nameIndex],*cast(uint*)comdat.data.ptr); 
    275273            } 
    276274             
     
    442440            foreach(idx,b; cast(ubyte[])(segdef.data)){ 
    443441                if(idx % 16 == 0){ 
    444                      result ~= sprint(" | %s\n\t [%0.8X] ",buf2,segdef.data.ptr+idx); 
     442                     result ~= sprint(" | %s\n [%0.8X] ",buf2,segdef.data.ptr+idx); 
    445443                     buf2 = ""; 
    446444                } 
     445                if(b < 16) result ~= "0"; //HACK: sprint doesn't left-pad correctly 
    447446                result ~= sprint("%0.2X ",b); 
    448447                if(b >= 32 && b <= 126){ 
    449                     buf2 ~= cast(char)b ~ " "
     448                    buf2 ~= cast(char)b
    450449                } 
    451450                else{ 
    452                     buf2 ~= ". "; 
     451                    buf2 ~= "."; 
    453452                } 
    454453            }