Changeset 39
- Timestamp:
- 02/12/12 11:05:27 (3 months ago)
- Files:
-
- downloads/cv2pdb_0.23.zip (added)
- downloads/cv2pdb_src_0.23.zip (added)
- trunk/CHANGES (modified) (2 diffs)
- trunk/INSTALL (modified) (1 diff)
- trunk/Makefile (modified) (1 diff)
- trunk/README (modified) (3 diffs)
- trunk/TODO (modified) (1 diff)
- trunk/VERSION (modified) (1 diff)
- trunk/autoexp.expand (modified) (1 diff)
- trunk/autoexp.visualizer (modified) (1 diff)
- trunk/src/PEImage.cpp (modified) (11 diffs)
- trunk/src/PEImage.h (modified) (5 diffs)
- trunk/src/cv2pdb.cpp (modified) (10 diffs)
- trunk/src/cv2pdb.h (modified) (9 diffs)
- trunk/src/cv2pdb.sln (modified) (1 diff)
- trunk/src/cv2pdb.vcproj (modified) (2 diffs)
- trunk/src/cvutil.cpp (modified) (2 diffs)
- trunk/src/cvutil.h (modified) (1 diff)
- trunk/src/dviewhelper/dviewhelper.cpp (modified) (3 diffs)
- trunk/src/dwarf.h (added)
- trunk/src/dwarf2pdb.cpp (added)
- trunk/src/main.cpp (modified) (4 diffs)
- trunk/src/symutil.cpp (modified) (2 diffs)
- trunk/src/symutil.h (modified) (2 diffs)
- trunk/test/cvtest.d (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/CHANGES
r38 r39 1 1 2 2 This is the CHANGES file for cv2pdb, a 3 converter of DMD CodeView debug information to PDB files3 converter of DMD CodeView/DWARF debug information to PDB files 4 4 5 Copyright (c) 2009-201 0by Rainer Schuetze, All Rights Reserved5 Copyright (c) 2009-2012 by Rainer Schuetze, All Rights Reserved 6 6 7 7 Version history … … 156 156 * added command line switch -s to specify the replacement character for '.' in symbols 157 157 * fixed another crash where compressed symbols expand to more than 4096 characters 158 159 2012-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 1 1 2 2 This is the INSTALL file for cv2pdb, a 3 converter of DMD CodeView debug information to PDB files3 converter of DMD CodeView/DWARF debug information to PDB files 4 4 5 5 Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved trunk/Makefile
r24 r39 22 22 src\demangle.cpp \ 23 23 src\demangle.h \ 24 src\dwarf2pdb.cpp \ 25 src\dwarf.h \ 24 26 src\LastError.h \ 25 27 src\main.cpp \ trunk/README
r23 r39 1 1 2 2 This is the README file for cv2pdb, a 3 converter of DMD CodeView debug information to PDB files3 converter of DMD CodeView/DWARF debug information to PDB files 4 4 5 5 Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved … … 15 15 -------- 16 16 * conversion of DMD CodeView information to PDB file 17 * conversion of DWARF information to PDB file 17 18 * converted line number info allows setting breakpoints 18 19 * display of variables, fields and objects in watch, local and auto window and in data tooltips … … 32 33 33 34 The file mscvpdb.h is taken from the WINE-project (http://www.winehq.org) 35 and is distributed under the terms of the GNU Lesser General Public 36 License as published by the Free Software Foundation; either 37 version 2.1 of the License, or (at your option) any later version. 38 See the file header for more details and 39 http://www.gnu.org/licenses/lgpl.html for the full license. 40 41 The file dwarf.h is taken from the libdwarf project 42 (http://reality.sgiweb.org/davea/dwarf.html) 34 43 and is distributed under the terms of the GNU Lesser General Public 35 44 License as published by the Free Software Foundation; either trunk/TODO
r35 r39 1 1 2 2 This is the TODO file for cv2pdb, a 3 converter of DMD CodeView debug information to PDB files3 converter of DMD CodeView/DWARF debug information to PDB files 4 4 5 5 Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved trunk/VERSION
r38 r39 1 VERSION = 0.2 21 VERSION = 0.23 trunk/autoexp.expand
r24 r39 10 10 11 11 object_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) 12 string=$ADDIN(dviewhelper.dll,_DStringView@28) 13 wstring=$ADDIN(dviewhelper.dll,_DWStringView@28) 14 dstring=$ADDIN(dviewhelper.dll,_DDStringView@28) 15 char[]=$ADDIN(dviewhelper.dll,_DStringView@28) 16 wchar[]=$ADDIN(dviewhelper.dll,_DWStringView@28) 17 dchar[]=$ADDIN(dviewhelper.dll,_DDStringView@28) 18 const(char)[]=$ADDIN(dviewhelper.dll,_DStringView@28) 19 const(wchar)[]=$ADDIN(dviewhelper.dll,_DWStringView@28) 20 const(dchar)[]=$ADDIN(dviewhelper.dll,_DDStringView@28) 21 const(char[])=$ADDIN(dviewhelper.dll,_DStringView@28) 22 const(wchar[])=$ADDIN(dviewhelper.dll,_DWStringView@28) 23 const(dchar[])=$ADDIN(dviewhelper.dll,_DDStringView@28) 24 immutable(char)[]=$ADDIN(dviewhelper.dll,_DStringView@28) 25 immutable(wchar)[]=$ADDIN(dviewhelper.dll,_DWStringView@28) 26 immutable(dchar)[]=$ADDIN(dviewhelper.dll,_DDStringView@28) 27 immutable(char[])=$ADDIN(dviewhelper.dll,_DStringView@28) 28 immutable(wchar[])=$ADDIN(dviewhelper.dll,_DWStringView@28) 29 immutable(dchar[])=$ADDIN(dviewhelper.dll,_DDStringView@28) 15 30 16 31 ;; eo section AutoExpand for D variables ;;;;;;;;;;;;;;;;;;;;;; trunk/autoexp.visualizer
r27 r39 10 10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 11 11 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 13 char[]|const(char)[]|immutable(char)[] { 14 preview ( [(string)$e] ) 15 } 16 17 wchar[]|const(wchar)[]|immutable(wchar)[] { 18 preview ( [(wstring)$e] ) 19 } 20 21 dchar[]|const(dchar)[]|immutable(dchar)[] { 22 preview ( [(dstring)$e] ) 56 23 } 57 24 trunk/src/PEImage.cpp
r27 r39 24 24 , dump_total_len(0) 25 25 , dirHeader(0) 26 , hdr32(0) 27 , hdr64(0) 26 28 , 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) 27 40 { 28 41 if(iname) … … 62 75 close(fd); 63 76 fd = -1; 64 return init Ptr(true);77 return initCVPtr(true) || initDWARFPtr(true); 65 78 } 66 79 … … 87 100 88 101 /////////////////////////////////////////////////////////////////////// 89 bool PEImage::replaceDebugSection (const void* data, int datalen )102 bool PEImage::replaceDebugSection (const void* data, int datalen, bool initCV) 90 103 { 91 104 // 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)); 93 110 int xdatalen = datalen + sizeof(debugdir); 94 111 … … 96 113 int s; 97 114 DWORD lastVirtualAddress = 0; 98 for(s = 0; s < hdr->FileHeader.NumberOfSections; s++) 115 int cntSections = countSections(); 116 for(s = 0; s < cntSections; s++) 99 117 { 100 118 if (strcmp ((char*) sec [s].Name, ".debug") == 0) 101 119 { 102 if (s == hdr->FileHeader.NumberOfSections - 1)120 if (s == cntSections - 1) 103 121 { 104 122 dump_total_len = sec[s].PointerToRawData; … … 111 129 } 112 130 113 int align = hdr->OptionalHeader.FileAlignment;131 int align = IMGHDR(OptionalHeader.FileAlignment); 114 132 int align_len = xdatalen; 115 133 int fill = 0; … … 125 143 126 144 int salign_len = xdatalen; 127 align = hdr->OptionalHeader.SectionAlignment;145 align = IMGHDR(OptionalHeader.SectionAlignment); 128 146 if (align > 0) 129 147 { … … 143 161 sec[s].Characteristics = IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE | IMAGE_SCN_CNT_INITIALIZED_DATA; 144 162 145 hdr->FileHeader.NumberOfSections= s + 1;163 IMGHDR(FileHeader.NumberOfSections) = s + 1; 146 164 // 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); 150 169 151 170 // append debug data chunk to existing file image … … 154 173 memcpy(newdata + dump_total_len + fill, data, datalen); 155 174 175 if(!dbgDir) 176 { 177 debugdir.Type = 2; 178 } 156 179 dbgDir = (IMAGE_DEBUG_DIRECTORY*) (newdata + dump_total_len + fill + datalen); 157 180 memcpy(dbgDir, &debugdir, sizeof(debugdir)); … … 170 193 dump_total_len += fill + xdatalen; 171 194 172 return initPtr(false);173 } 174 175 /////////////////////////////////////////////////////////////////////// 176 bool PEImage::init Ptr(bool initDbgDir)195 return !initCV || initCVPtr(false); 196 } 197 198 /////////////////////////////////////////////////////////////////////// 199 bool PEImage::initCVPtr(bool initDbgDir) 177 200 { 178 201 dos = DPV<IMAGE_DOS_HEADER> (0); … … 182 205 return setError("this is not a DOS executable"); 183 206 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) 186 210 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); 202 231 dbgDir = RVA<IMAGE_DEBUG_DIRECTORY>(off, 0x1c); 203 232 if (!dbgDir) … … 231 260 232 261 /////////////////////////////////////////////////////////////////////// 262 bool 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 328 int 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 /////////////////////////////////////////////////////////////////////// 233 339 int PEImage::countCVEntries() const 234 340 { trunk/src/PEImage.h
r22 r39 14 14 struct OMFDirHeader; 15 15 struct OMFDirEntry; 16 17 #define IMGHDR(x) (hdr32 ? hdr32->x : hdr64->x) 16 18 17 19 class PEImage : public LastError … … 58 60 bool save(const char* oname); 59 61 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; } 62 68 63 69 int countCVEntries() const; … … 70 76 static void free_aligned(void* p); 71 77 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 72 83 private: 73 84 int fd; … … 75 86 int dump_total_len; 76 87 88 // codeview 77 89 IMAGE_DOS_HEADER *dos; 78 IMAGE_NT_HEADERS32* hdr; 90 IMAGE_NT_HEADERS32* hdr32; 91 IMAGE_NT_HEADERS64* hdr64; 79 92 IMAGE_SECTION_HEADER* sec; 80 93 IMAGE_DEBUG_DIRECTORY* dbgDir; … … 82 95 OMFDirEntry* dirEntry; 83 96 97 public: 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; 84 112 int cv_base; 85 113 }; trunk/src/cv2pdb.cpp
r35 r39 23 23 , globalSymbols(0), cbGlobalSymbols(0), staticSymbols(0), cbStaticSymbols(0) 24 24 , udtSymbols(0), cbUdtSymbols(0), allocUdtSymbols(0) 25 , dwarfTypes(0), cbDwarfTypes(0), allocDwarfTypes(0) 25 26 , srcLineStart(0), srcLineSections(0) 26 27 , pointerTypes(0) … … 28 29 , classEnumType(0), ifaceEnumType(0), cppIfaceEnumType(0), structEnumType(0) 29 30 , classBaseType(0), ifaceBaseType(0), cppIfaceBaseType(0), structBaseType(0) 31 , emptyFieldListType(0) 30 32 { 31 33 memset(typedefs, 0, sizeof(typedefs)); 32 34 memset(translatedTypedefs, 0, sizeof(translatedTypedefs)); 33 35 cntTypedefs = 0; 36 nextUserType = 0x1000; 37 nextDwarfType = 0x1000; 34 38 35 39 addClassTypeEnum = true; 40 addStringViewHelper = false; 41 useTypedefEnum = false; 36 42 useGlobalMod = true; 37 43 thisIsNotRef = true; … … 75 81 if (udtSymbols) 76 82 free(udtSymbols); 83 if (dwarfTypes) 84 free(dwarfTypes); 77 85 delete [] pointerTypes; 78 86 … … 99 107 cbUdtSymbols = 0; 100 108 allocUdtSymbols = 0; 109 cbDwarfTypes = 0; 110 allocDwarfTypes = 0; 101 111 modules = 0; 102 112 globmod = 0; … … 787 797 if (cbUserTypes + size >= allocUserTypes) 788 798 { 789 allocUserTypes += add;799 allocUserTypes += size + add; 790 800 userTypes = (BYTE*) realloc(userTypes, allocUserTypes); 791 801 } … … 1397 1407 1398 1408 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)) 1400 1411 { 1401 1412 // nextUserType + 1: field list (size, array) … … 1732 1743 } 1733 1744 1745 int 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 1734 1763 int CV2PDB::appendComplex(int cplxtype, int basetype, int elemsize, const char* name) 1735 1764 { … … 1903 1932 } 1904 1933 1905 int CV2PDB::appendTypedef(int type, const char* name) 1906 { 1934 int CV2PDB::createEmptyFieldListType() 1935 { 1936 if(emptyFieldListType > 0) 1937 return emptyFieldListType; 1938 1907 1939 checkUserTypeAlloc(); 1908 1909 int basetype = type;1910 if(type == 0x78)1911 basetype = 0x75; // dchar type not understood by debugger, use uint instead1912 1913 1940 codeview_reftype* rdtype = (codeview_reftype*) (userTypes + cbUserTypes); 1914 1941 rdtype->fieldlist.id = LF_FIELDLIST_V2; 1915 1942 rdtype->fieldlist.len = 2; 1916 1943 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 1949 int 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; 1935 1984 } 1936 1985 … … 2935 2984 } 2936 2985 2986 void 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 2937 2995 bool CV2PDB::addUdtSymbol(int type, const char* name) 2938 2996 { 2939 if (cbUdtSymbols + 100 + kMaxNameLen > allocUdtSymbols) 2940 { 2941 allocUdtSymbols += kMaxNameLen + 5000; 2942 udtSymbols = (BYTE*) realloc(udtSymbols, allocUdtSymbols); 2943 } 2997 checkUdtSymbolAlloc(100 + kMaxNameLen); 2944 2998 2945 2999 // no need to convert to udt_v2/udt_v3, the debugger is fine with it. … … 3046 3100 { 3047 3101 int len = sizeof(*rsds) + strlen((char*)(rsds + 1)) + 1; 3048 if (!img.replaceDebugSection(rsds, len ))3102 if (!img.replaceDebugSection(rsds, len, true)) 3049 3103 return setError(img.getLastError()); 3050 3104 trunk/src/cv2pdb.h
r35 r39 12 12 13 13 #include <windows.h> 14 #include <map> 14 15 15 16 extern "C" { … … 18 19 19 20 class PEImage; 21 struct DWARF_InfoData; 22 struct DWARF_CompilationUnit; 20 23 21 24 class CV2PDB : public LastError … … 68 71 void checkUserTypeAlloc(int size = 1000, int add = 10000); 69 72 void checkGlobalTypeAlloc(int size, int add = 1000); 73 void checkUdtSymbolAlloc(int size, int add = 10000); 74 void checkDWARFTypeAlloc(int size, int add = 10000); 70 75 void writeUserTypeLen(codeview_type* type, int len); 71 76 … … 76 81 77 82 int findMemberFunctionType(codeview_symbol* lastGProcSym, int thisPtrType); 83 int createEmptyFieldListType(); 78 84 79 85 int fixProperty(int type, int prop, int fieldType); … … 107 113 int appendObjectType (int object_derived_type, int enumType, const char* classSymbol); 108 114 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); 110 117 int appendComplex(int cplxtype, int basetype, int elemsize, const char* name); 111 118 void appendTypedefs(); 112 119 int appendEnumerator(const char* typeName, const char* enumName, int enumValue, int prop); 113 120 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); 115 128 bool insertClassTypeEnums(); 116 129 int insertBaseClass(const codeview_type* fieldlist, int type); … … 144 157 mspdb::Mod* globalMod(); 145 158 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 146 180 // private: 147 181 BYTE* libraries; … … 184 218 int allocUdtSymbols; 185 219 220 unsigned char* dwarfTypes; 221 int cbDwarfTypes; 222 int allocDwarfTypes; 223 186 224 int nextUserType; 225 int nextDwarfType; 187 226 int objectType; 188 227 228 int emptyFieldListType; 189 229 int classEnumType; 190 230 int ifaceEnumType; … … 203 243 204 244 bool addClassTypeEnum; 245 bool addStringViewHelper; 205 246 bool useGlobalMod; 206 247 bool thisIsNotRef; … … 212 253 213 254 double Dversion; 255 256 // DWARF 257 int codeSegOff; 258 std::map<int, int> mapOffsetToType; 214 259 }; 215 260 trunk/src/cv2pdb.sln
r27 r39 25 25 EndProjectSection 26 26 EndProject 27 Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "test", "..\test\test.visualdproj", "{370E7494-D0CB-450F-B74A-4CEEDB19FBAE}" 28 EndProject 29 Project("{8BC9CEB9-8B4A-11D0-8D11-00A0C91BC942}") = "test64.exe", "..\bin\Debug GDCWin32\test64.exe", "{022545C9-DE2E-44F0-B87C-74CEAC3202F6}" 30 EndProject 27 31 Global 28 32 GlobalSection(SolutionConfigurationPlatforms) = preSolution 33 Debug GDC|Win32 = Debug GDC|Win32 34 Debug GDC|x64 = Debug GDC|x64 29 35 Debug|Win32 = Debug|Win32 36 Debug|x64 = Debug|x64 30 37 Release|Win32 = Release|Win32 38 Release|x64 = Release|x64 31 39 EndGlobalSection 32 40 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 33 44 {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug|Win32.ActiveCfg = Debug|Win32 34 45 {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug|Win32.Build.0 = Debug|Win32 46 {5E2BD27D-446A-4C99-9829-135F7C000D90}.Debug|x64.ActiveCfg = Debug|Win32 35 47 {5E2BD27D-446A-4C99-9829-135F7C000D90}.Release|Win32.ActiveCfg = Release|Win32 36 48 {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 37 53 {E4424774-A7A0-4502-8626-2723904D70EA}.Debug|Win32.ActiveCfg = Debug|Win32 38 54 {E4424774-A7A0-4502-8626-2723904D70EA}.Debug|Win32.Build.0 = Debug|Win32 55 {E4424774-A7A0-4502-8626-2723904D70EA}.Debug|x64.ActiveCfg = Debug|Win32 39 56 {E4424774-A7A0-4502-8626-2723904D70EA}.Release|Win32.ActiveCfg = Release|Win32 40 57 {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 41 62 {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug|Win32.ActiveCfg = Debug|Win32 42 63 {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug|Win32.Build.0 = Debug|Win32 64 {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Debug|x64.ActiveCfg = Debug|Win32 43 65 {CCC0643D-7D3F-4D5E-AE0E-C871776E86AF}.Release|Win32.ActiveCfg = Release|Win32 44 66 {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 45 86 EndGlobalSection 46 87 GlobalSection(SolutionProperties) = preSolution trunk/src/cv2pdb.vcproj
r35 r39 185 185 </File> 186 186 <File 187 RelativePath=".\cv2pdb.h" 188 > 189 </File> 190 <File 187 191 RelativePath=".\cvutil.cpp" 188 192 > … … 198 202 <File 199 203 RelativePath=".\demangle.h" 204 > 205 </File> 206 <File 207 RelativePath=".\dwarf2pdb.cpp" 200 208 > 201 209 </File> trunk/src/cvutil.cpp
r33 r39 111 111 { 112 112 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; 114 114 int length = 2; 115 115 … … 180 180 } 181 181 182 int 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 51 51 52 52 int numeric_leaf(int* value, const void* leaf); 53 int write_numeric_leaf(int value, void* leaf); 53 54 54 55 #endif // __CVUTIL_H__ trunk/src/dviewhelper/dviewhelper.cpp
r22 r39 26 26 { 27 27 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); 29 29 // from here only when dwVersion >= 0x20000 30 30 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); 32 32 int (WINAPI *GetProcessorType)(DEBUGHELPER *pThis); 33 33 }; 34 35 // possible processor types 36 typedef enum _MPT { 37 mptix86 = 0, // Intel X86 38 mptia64 = 1, // Intel Merced 39 mptamd64 = 2, // AMD64 40 mptUnknown = 3 // Unknown 41 } MPT; 42 43 HRESULT 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 } 34 49 35 50 struct DString … … 44 59 char *pResult, size_t max, DWORD sizePerChar) 45 60 { 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 46 70 // Get the string struct 47 DString dstr;71 char strdata[16]; 48 72 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) 50 74 { 51 strncpy(pResult,"Cannot access struct", max);52 return S_OK;75 strncpy(pResult,"Cannot access struct", max); 76 return S_OK; 53 77 } 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) 55 90 { 56 91 strncpy(pResult,"\"\"", max); … … 59 94 60 95 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); 62 97 if (sizePerChar * cnt > max) 63 98 pData = new char[sizePerChar * cnt]; 64 99 65 if ( pHelper->ReadDebuggeeMemory(pHelper, dstr.data, sizePerChar * cnt, pData, &read) != S_OK)100 if (readMem(pHelper, data, sizePerChar * cnt, pData, &read) != S_OK) 66 101 { 67 102 strncpy(pResult,"Cannot access data", max); trunk/src/main.cpp
r38 r39 82 82 if (argc < 2) 83 83 { 84 printf("Convert DMD CodeView debug information to PDB files, Version %g\n", VERSION);85 printf("Copyright (c) 2009-201 1by 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"); 86 86 printf("\n"); 87 87 printf("License for redistribution is given by the Artistic License 2.0\n"); … … 107 107 else if (argv[0][1] == 'n') 108 108 demangleSymbols = false; 109 else if (argv[0][1] == 'e') 110 useTypedefEnum = true; 109 111 else if (argv[0][1] == 's' && argv[0][2]) 110 112 dotReplacementChar = argv[0][2]; … … 115 117 if (!img.load(argv[1])) 116 118 fatal("%s: %s", argv[1], img.getLastError()); 117 if (img.countCVEntries() == 0)119 if (img.countCVEntries() == 0 && !img.hasDWARF()) 118 120 fatal("%s: no codeview debug entries found", argv[1]); 119 121 120 122 CV2PDB cv2pdb(img); 123 cv2pdb.Dversion = Dversion; 121 124 cv2pdb.initLibraries(); 122 cv2pdb.Dversion = Dversion;123 125 124 126 char* outname = argv[1]; … … 145 147 fatal("%s: %s", pdbname, cv2pdb.getLastError()); 146 148 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 } 173 198 174 199 return 0; trunk/src/symutil.cpp
r38 r39 16 16 char dotReplacementChar = '@'; 17 17 bool demangleSymbols = true; 18 bool useTypedefEnum = false; 18 19 19 20 int dsym2c(const BYTE* p, int len, char* cname, int maxclen) … … 142 143 { 143 144 return p2c(&p.namelen, idx); 145 } 146 147 int 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 164 int c2p(const char* c, p_string& p) 165 { 166 return c2p(c, &p.namelen); 144 167 } 145 168 trunk/src/symutil.h
r35 r39 20 20 char* p2c(const BYTE* p, int idx = 0); 21 21 char* p2c(const p_string& p, int idx = 0); 22 int c2p(const char* c, BYTE* p); // return byte len 23 int c2p(const char* c, p_string& p); 22 24 int p2ccpy(char* p, const BYTE* s); 23 25 int pstrcpy(BYTE* p, const BYTE* s); … … 32 34 extern char dotReplacementChar; 33 35 extern bool demangleSymbols; 36 extern bool useTypedefEnum; 34 37 35 38 #endif //__SYMUTIL_H__ trunk/test/cvtest.d
r35 r39 88 88 // LF_ARRAY_V1 89 89 long[4] global_fixed_array; 90 __gshared long[4] gshared_fixed_array = [ 1, 2, 3, 4 ]; 91 __gshared string gshared_bss_string; 90 92 91 93 // OEM types; … … 219 221 } 220 222 221 int arrays()223 size_t arrays() 222 224 { 223 225 int[] iarr; … … 229 231 const void[] cvarr; 230 232 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 231 238 return iarr.length; 239 } 240 241 size_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; 232 255 } 233 256 … … 251 274 class_staticmember inst_staticmember = new class_staticmember; 252 275 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; 254 277 struct_name inst_struct; 255 278 struct_name* pinst_struct; … … 267 290 CUnknown unkn = new CUnknown; 268 291 IUnknown iunkn = unkn; 269 CUnknown nunkn = cast(CUnknown) iunkn;292 // CUnknown nunkn = cast(CUnknown) iunkn; 270 293 271 294 FILE stdfile; … … 310 333 voidpointers(null); 311 334 arrays(); 335 lexical_scope(); 336 312 337 outer_func(3); 313 338 A.outer_func(3); 339 340 global_fixed_array[1] = 3; 341 gshared_fixed_array[0] = 3; 342 gshared_bss_string = "bss"; 314 343 315 344 main2(argv); … … 352 381 (new Test).test(); 353 382 354 dmd_quirks();383 basictypes(); 355 384 strings(); 356 385 … … 366 395 class Test 367 396 { 368 int test()397 size_t test() 369 398 { 370 399 class_outer clss = new class_outer; … … 385 414 int strings() 386 415 { 387 string cs = "char string"; 416 string empty; 417 string cs = "char string"; 388 418 wstring ws = "wchar string"w; 389 419 dstring ds = "dchar string"d; 390 420 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 391 441 return 0; 392 442 } 393 443 394 void dmd_quirks() 395 { 444 double 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; 396 456 long quirk_long; // written as delegate<void*,int> 397 457 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
