Changeset 39

Show
Ignore:
Timestamp:
02/12/12 11:05:27 (3 months ago)
Author:
sagitario
Message:
  • disabled named enumerator for D basic types to avoid debugger troubles displaying arrays
  • added command line switch -e to enable using named enumerator for D basic types
  • added DWARF support
  • added x64 support
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGES

    r38 r39  
    11 
    22This is the CHANGES file for cv2pdb, a  
    3 converter of DMD CodeView debug information to PDB files 
     3converter of DMD CodeView/DWARF debug information to PDB files 
    44 
    5 Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved 
     5Copyright (c) 2009-2012 by Rainer Schuetze, All Rights Reserved 
    66 
    77Version history 
     
    156156  * added command line switch -s to specify the replacement character for '.' in symbols 
    157157  * fixed another crash where compressed symbols expand to more than 4096 characters 
     158 
     1592012-02-12 Version 0.23 
     160 
     161  * disabled named enumerator for D basic types to avoid debugger troubles displaying arrays 
     162  * added command line switch -e to enable using named enumerator for D basic types 
     163  * added DWARF support 
     164  * added x64 support 
  • trunk/INSTALL

    r35 r39  
    11 
    22This is the INSTALL file for cv2pdb, a  
    3 converter of DMD CodeView debug information to PDB files 
     3converter of DMD CodeView/DWARF debug information to PDB files 
    44 
    55Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved 
  • trunk/Makefile

    r24 r39  
    2222      src\demangle.cpp \ 
    2323      src\demangle.h \ 
     24      src\dwarf2pdb.cpp \ 
     25      src\dwarf.h \ 
    2426      src\LastError.h \ 
    2527      src\main.cpp \ 
  • trunk/README

    r23 r39  
    11 
    22This is the README file for cv2pdb, a  
    3 converter of DMD CodeView debug information to PDB files 
     3converter of DMD CodeView/DWARF debug information to PDB files 
    44 
    55Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved 
     
    1515-------- 
    1616* conversion of DMD CodeView information to PDB file 
     17* conversion of DWARF information to PDB file 
    1718* converted line number info allows setting breakpoints 
    1819* display of variables, fields and objects in watch, local and auto window and in data tooltips 
     
    3233 
    3334The file mscvpdb.h is taken from the WINE-project (http://www.winehq.org) 
     35and is distributed under the terms of the GNU Lesser General Public 
     36License as published by the Free Software Foundation; either 
     37version 2.1 of the License, or (at your option) any later version. 
     38See the file header for more details and  
     39http://www.gnu.org/licenses/lgpl.html for the full license. 
     40 
     41The file dwarf.h is taken from the libdwarf project  
     42(http://reality.sgiweb.org/davea/dwarf.html) 
    3443and is distributed under the terms of the GNU Lesser General Public 
    3544License as published by the Free Software Foundation; either 
  • trunk/TODO

    r35 r39  
    11 
    22This is the TODO file for cv2pdb, a  
    3 converter of DMD CodeView debug information to PDB files 
     3converter of DMD CodeView/DWARF debug information to PDB files 
    44 
    55Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved 
  • trunk/VERSION

    r38 r39  
    1 VERSION = 0.22 
     1VERSION = 0.23 
  • trunk/autoexp.expand

    r24 r39  
    1010 
    1111object_viewhelper=$ADDIN(dviewhelper.dll,_DObjectView@28) 
    12 string_viewhelper=$ADDIN(dviewhelper.dll,_DStringView@28) 
    13 wstring_viewhelper=$ADDIN(dviewhelper.dll,_DWStringView@28) 
    14 dstring_viewhelper=$ADDIN(dviewhelper.dll,_DDStringView@28) 
     12string=$ADDIN(dviewhelper.dll,_DStringView@28) 
     13wstring=$ADDIN(dviewhelper.dll,_DWStringView@28) 
     14dstring=$ADDIN(dviewhelper.dll,_DDStringView@28) 
     15char[]=$ADDIN(dviewhelper.dll,_DStringView@28) 
     16wchar[]=$ADDIN(dviewhelper.dll,_DWStringView@28) 
     17dchar[]=$ADDIN(dviewhelper.dll,_DDStringView@28) 
     18const(char)[]=$ADDIN(dviewhelper.dll,_DStringView@28) 
     19const(wchar)[]=$ADDIN(dviewhelper.dll,_DWStringView@28) 
     20const(dchar)[]=$ADDIN(dviewhelper.dll,_DDStringView@28) 
     21const(char[])=$ADDIN(dviewhelper.dll,_DStringView@28) 
     22const(wchar[])=$ADDIN(dviewhelper.dll,_DWStringView@28) 
     23const(dchar[])=$ADDIN(dviewhelper.dll,_DDStringView@28) 
     24immutable(char)[]=$ADDIN(dviewhelper.dll,_DStringView@28) 
     25immutable(wchar)[]=$ADDIN(dviewhelper.dll,_DWStringView@28) 
     26immutable(dchar)[]=$ADDIN(dviewhelper.dll,_DDStringView@28) 
     27immutable(char[])=$ADDIN(dviewhelper.dll,_DStringView@28) 
     28immutable(wchar[])=$ADDIN(dviewhelper.dll,_DWStringView@28) 
     29immutable(dchar[])=$ADDIN(dviewhelper.dll,_DDStringView@28) 
    1530 
    1631;; eo section AutoExpand for D variables ;;;;;;;;;;;;;;;;;;;;;; 
  • trunk/autoexp.visualizer

    r27 r39  
    1010;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
    1111 
    12 ; string, wstring and dstring use __viewhelper 
    13 string|wstring|dstring { 
    14  
    15     preview (  
    16         #if ($e.ptr == 0) ( "null" ) 
    17         #else (  
    18             #( "[", $e.length, "] ", [$e.__viewhelper] ) 
    19         ) 
    20     ) 
    21     stringview (  
    22         #if ($e.ptr == 0) ( "null" ) 
    23         #else (  
    24             #( [$e.ptr, s] ) 
    25         ) 
    26     ) 
    27     children ( 
    28         #( 
    29             length: [$e.length, i], 
    30             data: [$e.ptr] 
    31         ) 
    32     ) 
    33 
    34  
    35 ; strings as dynamic arrays of char (no __viewhelper, check -D option for cv2pdb!) 
    36 const char[]|char[]|const wchar[]|wchar[]|const dchar[]|dchar[] { 
    37  
    38     preview (  
    39         #if ($e.ptr == 0) ( "null" ) 
    40         #else (  
    41             #( "[", $e.length, "] ", [$e.ptr] ) 
    42         ) 
    43     ) 
    44     stringview (  
    45         #if ($e.ptr == 0) ( "null" ) 
    46         #else (  
    47             #( [$e.ptr, s] ) 
    48         ) 
    49     ) 
    50     children ( 
    51         #( 
    52             length: [$e.length, i], 
    53             data: [$e.ptr] 
    54         ) 
    55     ) 
     12; strings not as dynamic arrays, use dviewhelper instead 
     13char[]|const(char)[]|immutable(char)[] { 
     14    preview ( [(string)$e] ) 
     15
     16         
     17wchar[]|const(wchar)[]|immutable(wchar)[] { 
     18    preview ( [(wstring)$e] ) 
     19
     20 
     21dchar[]|const(dchar)[]|immutable(dchar)[] { 
     22    preview ( [(dstring)$e] ) 
    5623} 
    5724 
  • trunk/src/PEImage.cpp

    r27 r39  
    2424, dump_total_len(0) 
    2525, dirHeader(0) 
     26, hdr32(0) 
     27, hdr64(0) 
    2628, fd(-1) 
     29, debug_aranges(0) 
     30, debug_pubnames(0) 
     31, debug_pubtypes(0) 
     32, debug_info(0) 
     33, debug_abbrev(0) 
     34, debug_line(0) 
     35, debug_frame(0) 
     36, debug_str(0) 
     37, debug_loc(0) 
     38, debug_ranges(0) 
     39, codeSegment(0) 
    2740{ 
    2841    if(iname) 
     
    6275    close(fd); 
    6376    fd = -1; 
    64     return initPtr(true); 
     77    return initCVPtr(true) || initDWARFPtr(true); 
    6578} 
    6679 
     
    87100 
    88101/////////////////////////////////////////////////////////////////////// 
    89 bool PEImage::replaceDebugSection (const void* data, int datalen
     102bool PEImage::replaceDebugSection (const void* data, int datalen, bool initCV
    90103{ 
    91104    // append new debug directory to data 
    92     IMAGE_DEBUG_DIRECTORY debugdir = *dbgDir; 
     105    IMAGE_DEBUG_DIRECTORY debugdir; 
     106    if(dbgDir) 
     107        debugdir = *dbgDir; 
     108    else 
     109        memset(&debugdir, 0, sizeof(debugdir)); 
    93110    int xdatalen = datalen + sizeof(debugdir); 
    94111 
     
    96113    int s; 
    97114    DWORD lastVirtualAddress = 0; 
    98     for(s = 0; s < hdr->FileHeader.NumberOfSections; s++) 
     115    int cntSections = countSections(); 
     116    for(s = 0; s < cntSections; s++) 
    99117    { 
    100118        if (strcmp ((char*) sec [s].Name, ".debug") == 0) 
    101119        { 
    102             if (s == hdr->FileHeader.NumberOfSections - 1) 
     120            if (s == cntSections - 1) 
    103121            { 
    104122                dump_total_len = sec[s].PointerToRawData; 
     
    111129    } 
    112130 
    113    int align = hdr->OptionalHeader.FileAlignment
     131    int align = IMGHDR(OptionalHeader.FileAlignment)
    114132    int align_len = xdatalen; 
    115133    int fill = 0; 
     
    125143 
    126144    int salign_len = xdatalen; 
    127    align = hdr->OptionalHeader.SectionAlignment
     145    align = IMGHDR(OptionalHeader.SectionAlignment)
    128146    if (align > 0) 
    129147    { 
     
    143161    sec[s].Characteristics = IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE | IMAGE_SCN_CNT_INITIALIZED_DATA; 
    144162 
    145     hdr->FileHeader.NumberOfSections = s + 1; 
     163    IMGHDR(FileHeader.NumberOfSections) = s + 1; 
    146164    // hdr->OptionalHeader.SizeOfImage += salign_len; 
    147     hdr->OptionalHeader.SizeOfImage = sec[s].VirtualAddress + salign_len; 
    148  
    149     hdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = lastVirtualAddress + datalen; 
     165    IMGHDR(OptionalHeader.SizeOfImage) = sec[s].VirtualAddress + salign_len; 
     166 
     167    IMGHDR(OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress) = lastVirtualAddress + datalen; 
     168    IMGHDR(OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size) = sizeof(IMAGE_DEBUG_DIRECTORY); 
    150169 
    151170    // append debug data chunk to existing file image 
     
    154173    memcpy(newdata + dump_total_len + fill, data, datalen); 
    155174 
     175    if(!dbgDir) 
     176    { 
     177        debugdir.Type = 2; 
     178    } 
    156179    dbgDir = (IMAGE_DEBUG_DIRECTORY*) (newdata + dump_total_len + fill + datalen); 
    157180    memcpy(dbgDir, &debugdir, sizeof(debugdir)); 
     
    170193    dump_total_len += fill + xdatalen; 
    171194 
    172     return initPtr(false); 
    173 } 
    174  
    175 /////////////////////////////////////////////////////////////////////// 
    176 bool PEImage::initPtr(bool initDbgDir) 
     195    return !initCV || initCVPtr(false); 
     196} 
     197 
     198/////////////////////////////////////////////////////////////////////// 
     199bool PEImage::initCVPtr(bool initDbgDir) 
    177200{ 
    178201    dos = DPV<IMAGE_DOS_HEADER> (0); 
     
    182205        return setError("this is not a DOS executable"); 
    183206 
    184     hdr = DPV<IMAGE_NT_HEADERS32> (dos->e_lfanew); 
    185     if(!hdr) 
     207    hdr32 = DPV<IMAGE_NT_HEADERS32> (dos->e_lfanew); 
     208    hdr64 = DPV<IMAGE_NT_HEADERS64> (dos->e_lfanew); 
     209    if(!hdr32) 
    186210        return setError("no optional header found"); 
    187  
    188     if(hdr->Signature != IMAGE_NT_SIGNATURE) 
    189         return setError("optional header does not have PE signature"); 
    190     if(hdr->FileHeader.SizeOfOptionalHeader < sizeof(IMAGE_OPTIONAL_HEADER32)) 
    191         return setError("optional header too small"); 
    192  
    193     sec = IMAGE_FIRST_SECTION(hdr); 
    194  
    195     if(hdr->OptionalHeader.NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_DEBUG) 
    196         return setError("too few entries in data directory"); 
    197  
    198     if(hdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size != 0x1c) 
    199         return setError("unexpected size of DEBUG data directory entry"); 
    200  
    201     int off = hdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress; 
     211    if(hdr32->FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64 || 
     212       hdr32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64) 
     213        hdr32 = 0; 
     214    else 
     215        hdr64 = 0; 
     216 
     217    if(IMGHDR(Signature) != IMAGE_NT_SIGNATURE) 
     218        return setError("optional header does not have PE signature"); 
     219    if(IMGHDR(FileHeader.SizeOfOptionalHeader) < sizeof(IMAGE_OPTIONAL_HEADER32)) 
     220        return setError("optional header too small"); 
     221 
     222    sec = hdr32 ? IMAGE_FIRST_SECTION(hdr32) : IMAGE_FIRST_SECTION(hdr64); 
     223 
     224    if(IMGHDR(OptionalHeader.NumberOfRvaAndSizes) <= IMAGE_DIRECTORY_ENTRY_DEBUG) 
     225        return setError("too few entries in data directory"); 
     226 
     227    if(IMGHDR(OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size) != 0x1c) 
     228        return setError("unexpected size of DEBUG data directory entry"); 
     229 
     230    int off = IMGHDR(OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress); 
    202231    dbgDir = RVA<IMAGE_DEBUG_DIRECTORY>(off, 0x1c); 
    203232    if (!dbgDir) 
     
    231260 
    232261/////////////////////////////////////////////////////////////////////// 
     262bool PEImage::initDWARFPtr(bool initDbgDir) 
     263{ 
     264    dos = DPV<IMAGE_DOS_HEADER> (0); 
     265    if(!dos) 
     266        return setError("file too small for DOS header"); 
     267    if(dos->e_magic != IMAGE_DOS_SIGNATURE) 
     268        return setError("this is not a DOS executable"); 
     269 
     270    hdr32 = DPV<IMAGE_NT_HEADERS32> (dos->e_lfanew); 
     271    hdr64 = DPV<IMAGE_NT_HEADERS64> (dos->e_lfanew); 
     272    if(!hdr32) 
     273        return setError("no optional header found"); 
     274    if(hdr32->FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64 || 
     275       hdr32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64) 
     276        hdr32 = 0; 
     277    else 
     278        hdr64 = 0; 
     279 
     280    if(IMGHDR(Signature) != IMAGE_NT_SIGNATURE) 
     281        return setError("optional header does not have PE signature"); 
     282    if(IMGHDR(FileHeader.SizeOfOptionalHeader) < sizeof(IMAGE_OPTIONAL_HEADER32)) 
     283        return setError("optional header too small"); 
     284 
     285    dbgDir = 0; 
     286    sec = hdr32 ? IMAGE_FIRST_SECTION(hdr32) : IMAGE_FIRST_SECTION(hdr64); 
     287    int nsec = IMGHDR(FileHeader.NumberOfSections); 
     288    const char* strtable = DPV<char>(IMGHDR(FileHeader.PointerToSymbolTable) + IMGHDR(FileHeader.NumberOfSymbols * IMAGE_SIZEOF_SYMBOL)); 
     289    for(int s = 0; s < nsec; s++) 
     290    { 
     291        const char* name = (const char*) sec[s].Name; 
     292        if(name[0] == '/') 
     293        { 
     294            int off = strtol(name + 1, 0, 10); 
     295            name = strtable + off; 
     296        } 
     297        if(strcmp(name, ".debug_aranges") == 0) 
     298            debug_aranges = DPV<char>(sec[s].PointerToRawData, sec[s].SizeOfRawData); 
     299        if(strcmp(name, ".debug_pubnames") == 0) 
     300            debug_pubnames = DPV<char>(sec[s].PointerToRawData, sec[s].SizeOfRawData); 
     301        if(strcmp(name, ".debug_pubtypes") == 0) 
     302            debug_pubtypes = DPV<char>(sec[s].PointerToRawData, sec[s].SizeOfRawData); 
     303        if(strcmp(name, ".debug_info") == 0) 
     304            debug_info = DPV<char>(sec[s].PointerToRawData, debug_info_length = sec[s].Misc.VirtualSize); 
     305        if(strcmp(name, ".debug_abbrev") == 0) 
     306            debug_abbrev = DPV<char>(sec[s].PointerToRawData, debug_abbrev_length = sec[s].Misc.VirtualSize); 
     307        if(strcmp(name, ".debug_line") == 0) 
     308            debug_line = DPV<char>(sec[s].PointerToRawData, debug_line_length = sec[s].Misc.VirtualSize); 
     309        if(strcmp(name, ".debug_frame") == 0) 
     310            debug_frame = DPV<char>(sec[s].PointerToRawData, sec[s].SizeOfRawData); 
     311        if(strcmp(name, ".debug_str") == 0) 
     312            debug_str = DPV<char>(sec[s].PointerToRawData, sec[s].SizeOfRawData); 
     313        if(strcmp(name, ".debug_loc") == 0) 
     314            debug_loc = DPV<char>(sec[s].PointerToRawData, sec[s].SizeOfRawData); 
     315        if(strcmp(name, ".debug_ranges") == 0) 
     316            debug_ranges = DPV<char>(sec[s].PointerToRawData, debug_ranges_length = sec[s].Misc.VirtualSize); 
     317        if(strcmp(name, ".reloc") == 0) 
     318            reloc = DPV<char>(sec[s].PointerToRawData, reloc_length = sec[s].Misc.VirtualSize); 
     319        if(strcmp(name, ".text") == 0) 
     320            codeSegment = s; 
     321    } 
     322 
     323    setError(0); 
     324 
     325    return true; 
     326} 
     327 
     328int PEImage::findSection(unsigned int off) const 
     329{ 
     330    off -= IMGHDR(OptionalHeader.ImageBase); 
     331    int nsec = IMGHDR(FileHeader.NumberOfSections); 
     332    for(int s = 0; s < nsec; s++) 
     333        if(sec[s].VirtualAddress <= off && off < sec[s].VirtualAddress + sec[s].Misc.VirtualSize) 
     334            return s; 
     335    return -1; 
     336} 
     337 
     338/////////////////////////////////////////////////////////////////////// 
    233339int PEImage::countCVEntries() const 
    234340{ 
  • trunk/src/PEImage.h

    r22 r39  
    1414struct OMFDirHeader; 
    1515struct OMFDirEntry; 
     16 
     17#define IMGHDR(x) (hdr32 ? hdr32->x : hdr64->x) 
    1618 
    1719class PEImage : public LastError 
     
    5860    bool save(const char* oname); 
    5961 
    60     bool replaceDebugSection (const void* data, int datalen); 
    61     bool initPtr(bool initDbgDir); 
     62    bool replaceDebugSection (const void* data, int datalen, bool initCV); 
     63    bool initCVPtr(bool initDbgDir); 
     64    bool initDWARFPtr(bool initDbgDir); 
     65 
     66    bool hasDWARF() const { return debug_line != 0; } 
     67    bool isX64() const { return hdr64 != 0; } 
    6268 
    6369    int countCVEntries() const; 
     
    7076    static void free_aligned(void* p); 
    7177 
     78    int countSections() const { return IMGHDR(FileHeader.NumberOfSections); } 
     79    int findSection(unsigned int off) const; 
     80    const IMAGE_SECTION_HEADER& getSection(int s) const { return sec[s]; } 
     81    unsigned long long getImageBase() const { return IMGHDR(OptionalHeader.ImageBase); } 
     82 
    7283private: 
    7384    int fd; 
     
    7586    int dump_total_len; 
    7687 
     88    // codeview 
    7789    IMAGE_DOS_HEADER *dos; 
    78     IMAGE_NT_HEADERS32* hdr; 
     90    IMAGE_NT_HEADERS32* hdr32; 
     91    IMAGE_NT_HEADERS64* hdr64; 
    7992    IMAGE_SECTION_HEADER* sec; 
    8093    IMAGE_DEBUG_DIRECTORY* dbgDir; 
     
    8295    OMFDirEntry* dirEntry; 
    8396     
     97public: 
     98    //dwarf 
     99    char* debug_aranges; 
     100    char* debug_pubnames; 
     101    char* debug_pubtypes; 
     102    char* debug_info;     unsigned long debug_info_length; 
     103    char* debug_abbrev;   unsigned long debug_abbrev_length; 
     104    char* debug_line;     unsigned long debug_line_length; 
     105    char* debug_frame; 
     106    char* debug_str; 
     107    char* debug_loc; 
     108    char* debug_ranges;   unsigned long debug_ranges_length; 
     109    char* reloc;          unsigned long reloc_length; 
     110 
     111    int codeSegment; 
    84112    int cv_base; 
    85113}; 
  • trunk/src/cv2pdb.cpp

    r35 r39  
    2323, globalSymbols(0), cbGlobalSymbols(0), staticSymbols(0), cbStaticSymbols(0) 
    2424, udtSymbols(0), cbUdtSymbols(0), allocUdtSymbols(0) 
     25, dwarfTypes(0), cbDwarfTypes(0), allocDwarfTypes(0) 
    2526, srcLineStart(0), srcLineSections(0) 
    2627, pointerTypes(0) 
     
    2829, classEnumType(0), ifaceEnumType(0), cppIfaceEnumType(0), structEnumType(0) 
    2930, classBaseType(0), ifaceBaseType(0), cppIfaceBaseType(0), structBaseType(0) 
     31, emptyFieldListType(0) 
    3032{ 
    3133    memset(typedefs, 0, sizeof(typedefs)); 
    3234    memset(translatedTypedefs, 0, sizeof(translatedTypedefs)); 
    3335    cntTypedefs = 0; 
     36    nextUserType = 0x1000; 
     37    nextDwarfType = 0x1000; 
    3438 
    3539    addClassTypeEnum = true; 
     40    addStringViewHelper = false; 
     41    useTypedefEnum = false; 
    3642    useGlobalMod = true; 
    3743    thisIsNotRef = true; 
     
    7581    if (udtSymbols) 
    7682        free(udtSymbols); 
     83    if (dwarfTypes) 
     84        free(dwarfTypes); 
    7785    delete [] pointerTypes; 
    7886 
     
    99107    cbUdtSymbols = 0; 
    100108    allocUdtSymbols = 0; 
     109    cbDwarfTypes = 0; 
     110    allocDwarfTypes = 0; 
    101111    modules = 0; 
    102112    globmod = 0; 
     
    787797    if (cbUserTypes + size >= allocUserTypes) 
    788798    { 
    789         allocUserTypes += add; 
     799        allocUserTypes += size + add; 
    790800        userTypes = (BYTE*) realloc(userTypes, allocUserTypes); 
    791801    } 
     
    13971407 
    13981408    int dstringType = 0; 
    1399     if(strcmp(name, "string") == 0 || strcmp(name, "wstring") == 0 || strcmp(name, "dstring") == 0) 
     1409    if(addStringViewHelper && 
     1410       (strcmp(name, "string") == 0 || strcmp(name, "wstring") == 0 || strcmp(name, "dstring") == 0)) 
    14001411    { 
    14011412        // nextUserType + 1: field list (size, array) 
     
    17321743} 
    17331744 
     1745int CV2PDB::appendModifierType(int type, int attr) 
     1746{ 
     1747    checkUserTypeAlloc(); 
     1748 
     1749    codeview_type* dtype = (codeview_type*) (userTypes + cbUserTypes); 
     1750    dtype->modifier_v2.id = LF_MODIFIER_V2; 
     1751    dtype->modifier_v2.type = translateType(type); 
     1752    dtype->modifier_v2.attribute = attr; 
     1753    int len = sizeof(dtype->modifier_v2); 
     1754    //for (; len & 3; len++) 
     1755    //  userTypes[cbUserTypes + len] = 0xf4 - (len & 3); 
     1756    dtype->modifier_v2.len = len - 2; 
     1757    cbUserTypes += len; 
     1758     
     1759    nextUserType++; 
     1760    return nextUserType - 1; 
     1761} 
     1762 
    17341763int CV2PDB::appendComplex(int cplxtype, int basetype, int elemsize, const char* name) 
    17351764{ 
     
    19031932} 
    19041933 
    1905 int CV2PDB::appendTypedef(int type, const char* name) 
    1906 
     1934int CV2PDB::createEmptyFieldListType() 
     1935
     1936    if(emptyFieldListType > 0) 
     1937        return emptyFieldListType; 
     1938 
    19071939    checkUserTypeAlloc(); 
    1908  
    1909     int basetype = type; 
    1910     if(type == 0x78) 
    1911         basetype = 0x75; // dchar type not understood by debugger, use uint instead 
    1912  
    19131940    codeview_reftype* rdtype = (codeview_reftype*) (userTypes + cbUserTypes); 
    19141941    rdtype->fieldlist.id = LF_FIELDLIST_V2; 
    19151942    rdtype->fieldlist.len = 2; 
    19161943    cbUserTypes += rdtype->fieldlist.len + 2; 
    1917     int fieldlistType = nextUserType++; 
    1918  
    1919     codeview_type* dtype = (codeview_type*) (userTypes + cbUserTypes); 
    1920     dtype->enumeration_v2.id = (v3 ? LF_ENUM_V3 : LF_ENUM_V2); 
    1921     dtype->enumeration_v2.type = basetype; 
    1922     dtype->enumeration_v2.fieldlist = fieldlistType; 
    1923     dtype->enumeration_v2.count = 0; 
    1924     dtype->enumeration_v2.property = kPropReserved2; 
    1925     int len = cstrcpy_v (v3, (BYTE*) &dtype->enumeration_v2.p_name, name); 
    1926     len += sizeof(dtype->enumeration_v2) - sizeof(dtype->enumeration_v2.p_name); 
    1927     writeUserTypeLen(dtype, len); 
    1928  
    1929     typedefs[cntTypedefs] = type; 
    1930     translatedTypedefs[cntTypedefs] = nextUserType; 
    1931     cntTypedefs++; 
    1932  
    1933     nextUserType++; 
    1934     return nextUserType - 1; 
     1944    emptyFieldListType = nextUserType++; 
     1945 
     1946    return emptyFieldListType; 
     1947
     1948 
     1949int CV2PDB::appendTypedef(int type, const char* name, bool saveTranslation) 
     1950
     1951    int basetype = type; 
     1952    if(type == 0x78) 
     1953        basetype = 0x75; // dchar type not understood by debugger, use uint instead 
     1954 
     1955    int typedefType; 
     1956    if(useTypedefEnum) 
     1957    { 
     1958        checkUserTypeAlloc(); 
     1959 
     1960        int fieldlistType = createEmptyFieldListType(); 
     1961 
     1962        codeview_type* dtype = (codeview_type*) (userTypes + cbUserTypes); 
     1963        dtype->enumeration_v2.id = (v3 ? LF_ENUM_V3 : LF_ENUM_V2); 
     1964        dtype->enumeration_v2.type = basetype; 
     1965        dtype->enumeration_v2.fieldlist = fieldlistType; 
     1966        dtype->enumeration_v2.count = 0; 
     1967        dtype->enumeration_v2.property = kPropReserved2; 
     1968        int len = cstrcpy_v (v3, (BYTE*) &dtype->enumeration_v2.p_name, name); 
     1969        len += sizeof(dtype->enumeration_v2) - sizeof(dtype->enumeration_v2.p_name); 
     1970        writeUserTypeLen(dtype, len); 
     1971        typedefType = nextUserType++; 
     1972    } 
     1973    else 
     1974    { 
     1975        typedefType = appendModifierType(type, 0); 
     1976    } 
     1977    if(saveTranslation) 
     1978    { 
     1979        typedefs[cntTypedefs] = type; 
     1980        translatedTypedefs[cntTypedefs] = typedefType; 
     1981        cntTypedefs++; 
     1982    } 
     1983    return typedefType; 
    19351984} 
    19361985 
     
    29352984} 
    29362985 
     2986void CV2PDB::checkUdtSymbolAlloc(int size, int add) 
     2987{ 
     2988    if (cbUdtSymbols + size > allocUdtSymbols) 
     2989    { 
     2990        allocUdtSymbols += size + add; 
     2991        udtSymbols = (BYTE*) realloc(udtSymbols, allocUdtSymbols); 
     2992    } 
     2993} 
     2994 
    29372995bool CV2PDB::addUdtSymbol(int type, const char* name) 
    29382996{ 
    2939     if (cbUdtSymbols + 100 + kMaxNameLen > allocUdtSymbols) 
    2940     { 
    2941         allocUdtSymbols += kMaxNameLen + 5000; 
    2942         udtSymbols = (BYTE*) realloc(udtSymbols, allocUdtSymbols); 
    2943     } 
     2997    checkUdtSymbolAlloc(100 + kMaxNameLen); 
    29442998 
    29452999    // no need to convert to udt_v2/udt_v3, the debugger is fine with it. 
     
    30463100{ 
    30473101    int len = sizeof(*rsds) + strlen((char*)(rsds + 1)) + 1; 
    3048     if (!img.replaceDebugSection(rsds, len)) 
     3102    if (!img.replaceDebugSection(rsds, len, true)) 
    30493103        return setError(img.getLastError()); 
    30503104 
  • trunk/src/cv2pdb.h

    r35 r39  
    1212 
    1313#include <windows.h> 
     14#include <map> 
    1415 
    1516extern "C" { 
     
    1819 
    1920class PEImage; 
     21struct DWARF_InfoData; 
     22struct DWARF_CompilationUnit; 
    2023 
    2124class CV2PDB : public LastError 
     
    6871    void checkUserTypeAlloc(int size = 1000, int add = 10000); 
    6972    void checkGlobalTypeAlloc(int size, int add = 1000); 
     73    void checkUdtSymbolAlloc(int size, int add = 10000); 
     74    void checkDWARFTypeAlloc(int size, int add = 10000); 
    7075    void writeUserTypeLen(codeview_type* type, int len); 
    7176 
     
    7681 
    7782    int findMemberFunctionType(codeview_symbol* lastGProcSym, int thisPtrType); 
     83    int createEmptyFieldListType(); 
    7884 
    7985    int fixProperty(int type, int prop, int fieldType); 
     
    107113    int  appendObjectType (int object_derived_type, int enumType, const char* classSymbol); 
    108114    int  appendPointerType(int pointedType, int attr); 
    109     int  appendTypedef(int type, const char* name); 
     115    int  appendModifierType(int type, int attr); 
     116    int  appendTypedef(int type, const char* name, bool saveTranslation = true); 
    110117    int  appendComplex(int cplxtype, int basetype, int elemsize, const char* name); 
    111118    void appendTypedefs(); 
    112119    int  appendEnumerator(const char* typeName, const char* enumName, int enumValue, int prop); 
    113120    int  appendClassTypeEnum(const codeview_type* fieldlist, int type, const char* name); 
    114     bool hasClassTypeEnum(const codeview_type* fieldlist); 
     121    void appendStackVar(const char* name, int type, int offset); 
     122    void appendGlobalVar(const char* name, int type, int seg, int offset); 
     123    bool appendEndArg(); 
     124    void appendEnd(); 
     125    void appendLexicalBlock(DWARF_InfoData& id, unsigned int proclo); 
     126 
     127    bool hasClassTypeEnum(const codeview_type* fieldlist); 
    115128    bool insertClassTypeEnums(); 
    116129    int  insertBaseClass(const codeview_type* fieldlist, int type); 
     
    144157    mspdb::Mod* globalMod(); 
    145158 
     159    // DWARF 
     160    bool createDWARFModules(); 
     161    unsigned char* getDWARFAbbrev(int off, int n); 
     162    bool addDWARFTypes(); 
     163    bool addDWARFLines(); 
     164    bool addDWARFPublics(); 
     165    bool relocateDebugLineInfo(); 
     166    bool writeDWARFImage(const char* opath); 
     167 
     168    bool addDWARFSectionContrib(mspdb::Mod* mod, unsigned long pclo, unsigned long pchi); 
     169    bool addDWARFProc(DWARF_InfoData& id, DWARF_CompilationUnit* cu, unsigned char* &locals, unsigned char* end); 
     170    int  addDWARFStructure(DWARF_InfoData& id, DWARF_CompilationUnit* cu, unsigned char* &locals, unsigned char* end); 
     171    int  addDWARFArray(DWARF_InfoData& arrayid, DWARF_CompilationUnit* cu, unsigned char* &locals, unsigned char* end); 
     172    int  addDWARFBasicType(const char*name, int encoding, int byte_size); 
     173    bool iterateDWARFDebugInfo(int op); 
     174    int  getTypeByDWARFOffset(DWARF_CompilationUnit* cu, int off); 
     175    int  getDWARFTypeSize(DWARF_CompilationUnit* cu, int typeOff); 
     176    int  getDWARFArrayBounds(DWARF_InfoData& arrayid, DWARF_CompilationUnit* cu,  
     177                             unsigned char* &locals, unsigned char* end, int& upperBound); 
     178    bool readDWARFInfoData(DWARF_InfoData& id, DWARF_CompilationUnit* cu, unsigned char* &p, bool mergeInfo = false); 
     179 
    146180// private: 
    147181    BYTE* libraries; 
     
    184218    int allocUdtSymbols; 
    185219 
     220    unsigned char* dwarfTypes; 
     221    int cbDwarfTypes; 
     222    int allocDwarfTypes; 
     223 
    186224    int nextUserType; 
     225    int nextDwarfType; 
    187226    int objectType; 
    188  
     227     
     228    int emptyFieldListType; 
    189229    int classEnumType; 
    190230    int ifaceEnumType; 
     
    203243 
    204244    bool addClassTypeEnum; 
     245    bool addStringViewHelper; 
    205246    bool useGlobalMod; 
    206247    bool thisIsNotRef; 
     
    212253 
    213254    double Dversion; 
     255 
     256    // DWARF 
     257    int codeSegOff; 
     258    std::map<int, int> mapOffsetToType; 
    214259}; 
    215260 
  • trunk/src/cv2pdb.sln

    r27 r39  
    2525    EndProjectSection 
    2626EndProject 
     27Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "test", "..\test\test.visualdproj", "{370E7494-D0CB-450F-B74A-4CEEDB19FBAE}" 
     28EndProject 
     29Project("{8BC9CEB9-8B4A-11D0-8D11-00A0C91BC942}") = "test64.exe", "..\bin\Debug GDCWin32\test64.exe", "{022545C9-DE2E-44F0-B87C-74CEAC3202F6}" 
     30EndProject 
    2731Global 
    2832    GlobalSection(SolutionConfigurationPlatforms) = preSolution 
     33        Debug GDC|Win32 = Debug GDC|Win32 
     34        Debug GDC|x64 = Debug GDC|x64 
    2935        Debug|Win32 = Debug|Win32 
     36        Debug|x64 = Debug|x64 
    3037        Release|Win32 = Release|Win32 
     38        Release|x64 = Release|x64 
    3139    EndGlobalSection 
    3240    GlobalSection(ProjectConfigurationPlatforms) = postSolution 
     41        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug GDC|Win32.ActiveCfg = Debug|Win32 
     42        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug GDC|Win32.Build.0 = Debug|Win32 
     43        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug GDC|x64.ActiveCfg = Debug|Win32 
    3344        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug|Win32.ActiveCfg = Debug|Win32 
    3445        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug|Win32.Build.0 = Debug|Win32 
     46        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug|x64.ActiveCfg = Debug|Win32 
    3547        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Release|Win32.ActiveCfg = Release|Win32 
    3648        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Release|Win32.Build.0 = Release|Win32 
     49        {5E2BD27D-446A-4C99-9829-135F7C000D90}.Release|x64.ActiveCfg = Release|Win32 
     50        {E4424774-A7A0-4502-8626-2723904D70EA}.Debug GDC|Win32.ActiveCfg = Debug|Win32 
     51        {E4424774-A7A0-4502-8626-2723904D70EA}.Debug GDC|Win32.Build.0 = Debug|Win32 
     52        {E4424774-A7A0-4502-8626-2723904D70EA}.Debug GDC|x64.ActiveCfg = Debug|Win32 
    3753        {E4424774-A7A0-4502-8626-2723904D70EA}.Debug|Win32.ActiveCfg = Debug|Win32 
    3854        {E4424774-A7A0-4502-8626-2723904D70EA}.Debug|Win32.Build.0 = Debug|Win32 
     55        {E4424774-A7A0-4502-8626-2723904D70EA}.Debug|x64.ActiveCfg = Debug|Win32 
    3956        {E4424774-A7A0-4502-8626-2723904D70EA}.Release|Win32.ActiveCfg = Release|Win32 
    4057        {E4424774-A7A0-4502-8626-2723904D70EA}.Release|Win32.Build.0 = Release|Win32 
     58        {E4424774-A7A0-4502-8626-2723904D70EA}.Release|x64.ActiveCfg = Release|Win32 
     59        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug GDC|Win32.ActiveCfg = Debug|Win32 
     60        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug GDC|Win32.Build.0 = Debug|Win32 
     61        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug GDC|x64.ActiveCfg = Debug|Win32 
    4162        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug|Win32.ActiveCfg = Debug|Win32 
    4263        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug|Win32.Build.0 = Debug|Win32 
     64        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug|x64.ActiveCfg = Debug|Win32 
    4365        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Release|Win32.ActiveCfg = Release|Win32 
    4466        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Release|Win32.Build.0 = Release|Win32 
     67        {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Release|x64.ActiveCfg = Release|Win32 
     68        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug GDC|Win32.ActiveCfg = Debug GDC|Win32 
     69        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug GDC|Win32.Build.0 = Debug GDC|Win32 
     70        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug GDC|x64.ActiveCfg = Debug GDC|x64 
     71        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug GDC|x64.Build.0 = Debug GDC|x64 
     72        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug|Win32.ActiveCfg = Debug|Win32 
     73        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug|Win32.Build.0 = Debug|Win32 
     74        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug|x64.ActiveCfg = Debug|x64 
     75        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Debug|x64.Build.0 = Debug|x64 
     76        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Release|Win32.ActiveCfg = Release|Win32 
     77        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Release|Win32.Build.0 = Release|Win32 
     78        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Release|x64.ActiveCfg = Release|x64 
     79        {370E7494-D0CB-450F-B74A-4CEEDB19FBAE}.Release|x64.Build.0 = Release|x64 
     80        {022545C9-DE2E-44F0-B87C-74CEAC3202F6}.Debug GDC|Win32.ActiveCfg = Debug 
     81        {022545C9-DE2E-44F0-B87C-74CEAC3202F6}.Debug GDC|x64.ActiveCfg = Debug 
     82        {022545C9-DE2E-44F0-B87C-74CEAC3202F6}.Debug|Win32.ActiveCfg = Debug 
     83        {022545C9-DE2E-44F0-B87C-74CEAC3202F6}.Debug|x64.ActiveCfg = Debug 
     84        {022545C9-DE2E-44F0-B87C-74CEAC3202F6}.Release|Win32.ActiveCfg = Debug 
     85        {022545C9-DE2E-44F0-B87C-74CEAC3202F6}.Release|x64.ActiveCfg = Debug 
    4586    EndGlobalSection 
    4687    GlobalSection(SolutionProperties) = preSolution 
  • trunk/src/cv2pdb.vcproj

    r35 r39  
    185185            </File> 
    186186            <File 
     187                RelativePath=".\cv2pdb.h" 
     188                > 
     189            </File> 
     190            <File 
    187191                RelativePath=".\cvutil.cpp" 
    188192                > 
     
    198202            <File 
    199203                RelativePath=".\demangle.h" 
     204                > 
     205            </File> 
     206            <File 
     207                RelativePath=".\dwarf2pdb.cpp" 
    200208                > 
    201209            </File> 
  • trunk/src/cvutil.cpp

    r33 r39  
    111111{ 
    112112    unsigned short int type = *(const unsigned short int*) leaf; 
    113     leaf = (const unsigned short int*) leaf + 2
     113    leaf = (const unsigned short int*) leaf + 1
    114114    int length = 2; 
    115115 
     
    180180} 
    181181 
     182int write_numeric_leaf(int value, void* leaf) 
     183{ 
     184    if(value >= 0 && value < LF_NUMERIC) 
     185    { 
     186        *(unsigned short int*) leaf = (unsigned short) value; 
     187        return 2; 
     188    } 
     189    unsigned short int* type = (unsigned short int*) leaf; 
     190    leaf = type + 1; 
     191    if (value >= -128 && value <= 127) 
     192    { 
     193        *type = LF_CHAR; 
     194        *(char*) leaf = (char)value; 
     195        return 3; 
     196    } 
     197    if (value >= -32768 && value <= 32767) 
     198    { 
     199        *type = LF_SHORT; 
     200        *(short*) leaf = (short)value; 
     201        return 4; 
     202    } 
     203    if (value >= 0 && value <= 65535) 
     204    { 
     205        *type = LF_USHORT; 
     206        *(unsigned short*) leaf = (unsigned short)value; 
     207        return 4; 
     208    } 
     209    *type = LF_LONG; 
     210    *(long*) leaf = (long)value; 
     211    return 6; 
     212} 
     213 
  • trunk/src/cvutil.h

    r35 r39  
    5151 
    5252int numeric_leaf(int* value, const void* leaf); 
     53int write_numeric_leaf(int value, void* leaf); 
    5354 
    5455#endif // __CVUTIL_H__ 
  • trunk/src/dviewhelper/dviewhelper.cpp

    r22 r39  
    2626{ 
    2727    DWORD dwVersion; 
    28     BOOL      (WINAPI *ReadDebuggeeMemory)(DEBUGHELPER *pThis, DWORD dwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot); 
     28    HRESULT   (WINAPI *ReadDebuggeeMemory)(DEBUGHELPER *pThis, DWORD dwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot); 
    2929    // from here only when dwVersion >= 0x20000 
    3030    DWORDLONG (WINAPI *GetRealAddress)(DEBUGHELPER *pThis); 
    31     BOOL      (WINAPI *ReadDebuggeeMemoryEx)(DEBUGHELPER *pThis, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot); 
     31    HRESULT   (WINAPI *ReadDebuggeeMemoryEx)(DEBUGHELPER *pThis, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot); 
    3232    int       (WINAPI *GetProcessorType)(DEBUGHELPER *pThis); 
    3333}; 
     34 
     35// possible processor types 
     36typedef enum _MPT { 
     37    mptix86 = 0,    // Intel X86 
     38    mptia64 = 1,   // Intel Merced 
     39    mptamd64 = 2,   // AMD64 
     40    mptUnknown = 3   // Unknown 
     41} MPT; 
     42 
     43HRESULT readMem(DEBUGHELPER *pHelper, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot) 
     44{ 
     45    if(pHelper->dwVersion < 0x20000) 
     46        return pHelper->ReadDebuggeeMemory(pHelper, (DWORD)qwAddr, nWant, pWhere, nGot); 
     47    return pHelper->ReadDebuggeeMemoryEx(pHelper, qwAddr, nWant, pWhere, nGot); 
     48} 
    3449 
    3550struct DString 
     
    4459                          char *pResult, size_t max, DWORD sizePerChar) 
    4560{ 
     61    DWORDLONG qwAddress = dwAddress;  
     62    if(pHelper->dwVersion >= 0x20000) 
     63        qwAddress = pHelper->GetRealAddress(pHelper); 
     64 
     65    int proc = 0; 
     66    if(pHelper->dwVersion >= 0x20000) 
     67        proc = pHelper->GetProcessorType(pHelper); 
     68    int sizeOfPtr = proc == 0 ? 4 : 8; 
     69 
    4670    // Get the string struct 
    47    DString dstr
     71    char strdata[16]
    4872    DWORD read; 
    49     if (pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(dstr), &dstr, &read) != S_OK)  
     73    if (readMem(pHelper, qwAddress, 2*sizeOfPtr, strdata, &read) != S_OK)  
    5074    { 
    51        strncpy(pResult,"Cannot access struct", max); 
    52        return S_OK; 
     75        strncpy(pResult,"Cannot access struct", max); 
     76        return S_OK; 
    5377    } 
    54     if (dstr.length == 0)  
     78    DWORDLONG length, data; 
     79    if(sizeOfPtr > 4) 
     80    { 
     81        length = *(DWORDLONG*) strdata; 
     82        data = *(DWORDLONG*) (strdata + sizeOfPtr); 
     83    } 
     84    else 
     85    { 
     86        length = *(DWORD*) strdata; 
     87        data = *(DWORD*) (strdata + sizeOfPtr); 
     88    } 
     89    if (length == 0)  
    5590    { 
    5691        strncpy(pResult,"\"\"", max); 
     
    5994 
    6095    char* pData = pResult + 1; 
    61     DWORD cnt = (dstr.length < max - 3 ? dstr.length : max - 3); 
     96    DWORD cnt = (length < max - 3 ? (DWORD)length : max - 3); 
    6297    if (sizePerChar * cnt > max) 
    6398        pData = new char[sizePerChar * cnt]; 
    6499 
    65     if (pHelper->ReadDebuggeeMemory(pHelper, dstr.data, sizePerChar * cnt, pData, &read) != S_OK)  
     100    if (readMem(pHelper, data, sizePerChar * cnt, pData, &read) != S_OK)  
    66101    { 
    67102        strncpy(pResult,"Cannot access data", max); 
  • trunk/src/main.cpp

    r38 r39  
    8282    if (argc < 2) 
    8383    { 
    84         printf("Convert DMD CodeView debug information to PDB files, Version %g\n", VERSION); 
    85         printf("Copyright (c) 2009-2011 by Rainer Schuetze, All Rights Reserved\n"); 
     84        printf("Convert DMD CodeView/DWARF debug information to PDB files, Version %g\n", VERSION); 
     85        printf("Copyright (c) 2009-2012 by Rainer Schuetze, All Rights Reserved\n"); 
    8686        printf("\n"); 
    8787        printf("License for redistribution is given by the Artistic License 2.0\n"); 
     
    107107        else if (argv[0][1] == 'n') 
    108108            demangleSymbols = false; 
     109        else if (argv[0][1] == 'e') 
     110            useTypedefEnum = true; 
    109111        else if (argv[0][1] == 's' && argv[0][2]) 
    110112            dotReplacementChar = argv[0][2]; 
     
    115117    if (!img.load(argv[1])) 
    116118        fatal("%s: %s", argv[1], img.getLastError()); 
    117    if (img.countCVEntries() == 0
     119    if (img.countCVEntries() == 0 && !img.hasDWARF()
    118120        fatal("%s: no codeview debug entries found", argv[1]); 
    119121 
    120122    CV2PDB cv2pdb(img); 
     123    cv2pdb.Dversion = Dversion; 
    121124    cv2pdb.initLibraries(); 
    122     cv2pdb.Dversion = Dversion; 
    123125 
    124126    char* outname = argv[1]; 
     
    145147        fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
    146148 
    147     if (!cv2pdb.initSegMap()) 
    148         fatal("%s: %s", argv[1], cv2pdb.getLastError()); 
    149  
    150     if (!cv2pdb.initGlobalSymbols()) 
    151         fatal("%s: %s", argv[1], cv2pdb.getLastError()); 
    152  
    153     if (!cv2pdb.initGlobalTypes()) 
    154         fatal("%s: %s", argv[1], cv2pdb.getLastError()); 
    155  
    156     if (!cv2pdb.createModules()) 
    157         fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
    158  
    159     if (!cv2pdb.addTypes()) 
    160         fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
    161  
    162     if (!cv2pdb.addSymbols()) 
    163         fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
    164  
    165     if (!cv2pdb.addSrcLines()) 
    166         fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
    167  
    168     if (!cv2pdb.addPublics()) 
    169         fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
    170  
    171     if (!cv2pdb.writeImage(outname)) 
    172         fatal("%s: %s", outname, cv2pdb.getLastError()); 
     149    if(img.hasDWARF()) 
     150    { 
     151        if(!cv2pdb.relocateDebugLineInfo()) 
     152            fatal("%s: %s", argv[1], cv2pdb.getLastError()); 
     153 
     154        if(!cv2pdb.createDWARFModules()) 
     155            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     156 
     157        if(!cv2pdb.addDWARFTypes()) 
     158            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     159 
     160        if(!cv2pdb.addDWARFLines()) 
     161            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     162 
     163        if (!cv2pdb.addDWARFPublics()) 
     164            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     165 
     166        if (!cv2pdb.writeDWARFImage(outname)) 
     167            fatal("%s: %s", outname, cv2pdb.getLastError()); 
     168    } 
     169    else 
     170    { 
     171        if (!cv2pdb.initSegMap()) 
     172            fatal("%s: %s", argv[1], cv2pdb.getLastError()); 
     173 
     174        if (!cv2pdb.initGlobalSymbols()) 
     175            fatal("%s: %s", argv[1], cv2pdb.getLastError()); 
     176 
     177        if (!cv2pdb.initGlobalTypes()) 
     178            fatal("%s: %s", argv[1], cv2pdb.getLastError()); 
     179 
     180        if (!cv2pdb.createModules()) 
     181            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     182 
     183        if (!cv2pdb.addTypes()) 
     184            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     185 
     186        if (!cv2pdb.addSymbols()) 
     187            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     188 
     189        if (!cv2pdb.addSrcLines()) 
     190            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     191 
     192        if (!cv2pdb.addPublics()) 
     193            fatal("%s: %s", pdbname, cv2pdb.getLastError()); 
     194 
     195        if (!cv2pdb.writeImage(outname)) 
     196            fatal("%s: %s", outname, cv2pdb.getLastError()); 
     197    } 
    173198 
    174199    return 0; 
  • trunk/src/symutil.cpp

    r38 r39  
    1616char dotReplacementChar = '@'; 
    1717bool demangleSymbols = true; 
     18bool useTypedefEnum = false; 
    1819 
    1920int dsym2c(const BYTE* p, int len, char* cname, int maxclen) 
     
    142143{ 
    143144    return p2c(&p.namelen, idx); 
     145} 
     146 
     147int c2p(const char* c, BYTE* p) 
     148{ 
     149    BYTE* q = p; 
     150    int len = strlen(c); 
     151    if(len > 255) 
     152    { 
     153        *p++ = 0xff; 
     154        *p++ = 0; 
     155        *p++ = len & 0xff; 
     156        *p++ = len >> 8; 
     157    } 
     158    else 
     159        *p++ = len; 
     160    memcpy(p, c, len); 
     161    return p + len - q; 
     162} 
     163 
     164int c2p(const char* c, p_string& p) 
     165{ 
     166    return c2p(c, &p.namelen); 
    144167} 
    145168 
  • trunk/src/symutil.h

    r35 r39  
    2020char* p2c(const BYTE* p, int idx = 0); 
    2121char* p2c(const p_string& p, int idx = 0); 
     22int c2p(const char* c, BYTE* p); // return byte len 
     23int c2p(const char* c, p_string& p); 
    2224int p2ccpy(char* p, const BYTE* s); 
    2325int pstrcpy(BYTE* p, const BYTE* s); 
     
    3234extern char dotReplacementChar; 
    3335extern bool demangleSymbols; 
     36extern bool useTypedefEnum; 
    3437 
    3538#endif //__SYMUTIL_H__ 
  • trunk/test/cvtest.d

    r35 r39  
    8888// LF_ARRAY_V1 
    8989long[4] global_fixed_array; 
     90__gshared long[4] gshared_fixed_array = [ 1, 2, 3, 4 ]; 
     91__gshared string gshared_bss_string; 
    9092 
    9193// OEM types; 
     
    219221} 
    220222 
    221 int arrays() 
     223size_t arrays() 
    222224{ 
    223225    int[] iarr; 
     
    229231    const void[] cvarr; 
    230232     
     233    int[7] xarr = [ 1, 2, 3, 4, 5, 6, 7 ]; 
     234    string[7] sarr = [ "a", "b", "c", "d", "e", "f", "g" ]; 
     235    wstring[7] wsarr = [ "a", "b", "c", "d", "e", "f", "g" ]; 
     236    dstring[7] dsarr = [ "a", "b", "c", "d", "e", "f", "g" ]; 
     237 
    231238    return iarr.length; 
     239} 
     240 
     241size_t lexical_scope() 
     242{ 
     243    int[10] arr1; 
     244    for(int i = 0; i < 10; i++) 
     245        arr1[i] = i; 
     246 
     247    for(int i = 0; i < 10; i++) 
     248        arr1[i] += i; 
     249 
     250    foreach(i; "hello") 
     251        if(i == 'e') 
     252            break; 
     253 
     254    return arr1.length; 
    232255} 
    233256 
     
    251274    class_staticmember inst_staticmember = new class_staticmember; 
    252275    class_outer inst_outer = new class_outer; 
    253     class_outer.class_inner inst_inner = inst_outer.inner; // = new class_outer.class_inner(inst_outer)
     276    class_outer.class_inner inst_inner = /*inst_outer.inner; // =*/ inst_outer.new class_inner
    254277    struct_name inst_struct; 
    255278    struct_name* pinst_struct; 
     
    267290    CUnknown unkn = new CUnknown; 
    268291    IUnknown iunkn = unkn; 
    269   CUnknown nunkn = cast(CUnknown) iunkn; 
     292//    CUnknown nunkn = cast(CUnknown) iunkn; 
    270293     
    271294    FILE stdfile; 
     
    310333    voidpointers(null); 
    311334    arrays(); 
     335    lexical_scope(); 
     336 
    312337    outer_func(3); 
    313338    A.outer_func(3); 
     339 
     340    global_fixed_array[1] = 3; 
     341    gshared_fixed_array[0] = 3; 
     342    gshared_bss_string = "bss"; 
    314343 
    315344    main2(argv); 
     
    352381    (new Test).test(); 
    353382 
    354     dmd_quirks(); 
     383    basictypes(); 
    355384    strings(); 
    356385 
     
    366395class Test 
    367396{ 
    368     int test() 
     397    size_t test() 
    369398    { 
    370399        class_outer clss = new class_outer; 
     
    385414int strings() 
    386415{ 
    387     string cs = "char string"; 
     416    string empty; 
     417    string  cs = "char string"; 
    388418    wstring ws = "wchar string"w; 
    389419    dstring ds = "dchar string"d; 
    390420 
     421    immutable(char)[]  ics = cs; 
     422    immutable(wchar)[] iws = ws; 
     423    immutable(dchar)[] ids = ds; 
     424 
     425    char[]  mcs = cs.dup; 
     426    wchar[] mws = ws.dup; 
     427    dchar[] mds = ds.dup; 
     428 
     429    const(char)[]  ccs = cs; 
     430    const(wchar)[] cws = ws; 
     431    const(dchar)[] cds = ds; 
     432 
     433    immutable char[]  i2cs = cs; 
     434    immutable wchar[] i2ws = ws; 
     435    immutable dchar[] i2ds = ds; 
     436 
     437    const char[]  c2cs = cs; 
     438    const wchar[] c2ws = ws; 
     439    const dchar[] c2ds = ds; 
     440 
    391441    return 0; 
    392442} 
    393443 
    394 void dmd_quirks() 
    395 
     444double basictypes() 
     445
     446    // basic types 
     447    char c; 
     448    wchar wc; 
     449    dchar dc; 
     450    byte b; 
     451    ubyte ub; 
     452    short s; 
     453    ushort us; 
     454    int i; 
     455    uint ui; 
    396456    long quirk_long; // written as delegate<void*,int> 
    397457    ulong quirk_ulong; // written as int[] 
    398 
    399  
     458 
     459    float f; 
     460    double d; 
     461    real r; 
     462 
     463    ifloat iflt; 
     464    idouble id; 
     465    ireal ir; 
     466    cfloat cf; 
     467    cdouble cd; 
     468    creal cr; 
     469 
     470    return f + d + r + cf.im; 
     471
     472