summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsagitario <sagitario@fc51e93f-b9fe-4711-8d8d-3ae870c5f7d8>2012-05-01 16:13:31 (GMT)
committersagitario <sagitario@fc51e93f-b9fe-4711-8d8d-3ae870c5f7d8>2012-05-01 16:13:31 (GMT)
commitdd308fa75adfe87dbff2201f60972ecadfe14e68 (patch)
tree392825c41e06a3789b4126486f4a0c45e0a711b6 /src
parent892b58bf895da2a527cf32953207f4d127d1d909 (diff)
downloadcv2pdb-dd308fa75adfe87dbff2201f60972ecadfe14e68.zip
cv2pdb-dd308fa75adfe87dbff2201f60972ecadfe14e68.tar.gz
cv2pdb-dd308fa75adfe87dbff2201f60972ecadfe14e68.tar.bz2
Version 0.24
* supports unicode characters in file names * improve interpretation of DWARF location expression
Diffstat (limited to 'src')
-rw-r--r--src/PEImage.cpp18
-rw-r--r--src/PEImage.h6
-rw-r--r--src/cv2pdb.cpp16
-rw-r--r--src/cv2pdb.h6
-rw-r--r--src/cv2pdb.vcproj7
-rw-r--r--src/dwarf2pdb.cpp111
-rw-r--r--src/main.cpp142
-rw-r--r--src/mspdb.cpp2
-rw-r--r--src/mspdb.h2
9 files changed, 177 insertions, 133 deletions
diff --git a/src/PEImage.cpp b/src/PEImage.cpp
index 1a9afbd..c2c01c5 100644
--- a/src/PEImage.cpp
+++ b/src/PEImage.cpp
@@ -18,8 +18,16 @@ extern "C" {
#include <share.h>
#include <sys/stat.h>
+#ifdef UNICODE
+#define T_sopen _wsopen
+#define T_open _wopen
+#else
+#define T_sopen sopen
+#define T_open open
+#endif
+
///////////////////////////////////////////////////////////////////////
-PEImage::PEImage(const char* iname)
+PEImage::PEImage(const TCHAR* iname)
: dump_base(0)
, dump_total_len(0)
, dirHeader(0)
@@ -51,12 +59,12 @@ PEImage::~PEImage()
}
///////////////////////////////////////////////////////////////////////
-bool PEImage::load(const char* iname)
+bool PEImage::load(const TCHAR* iname)
{
if (fd != -1)
return setError("file already open");
- fd = sopen(iname, O_RDONLY | O_BINARY, SH_DENYWR);
+ fd = T_sopen(iname, O_RDONLY | O_BINARY, SH_DENYWR);
if (fd == -1)
return setError("Can't open file");
@@ -78,7 +86,7 @@ bool PEImage::load(const char* iname)
}
///////////////////////////////////////////////////////////////////////
-bool PEImage::save(const char* oname)
+bool PEImage::save(const TCHAR* oname)
{
if (fd != -1)
return setError("file already open");
@@ -86,7 +94,7 @@ bool PEImage::save(const char* oname)
if (!dump_base)
return setError("no data to dump");
- fd = open(oname, O_WRONLY | O_CREAT | O_BINARY | O_TRUNC, S_IREAD | S_IWRITE | S_IEXEC);
+ fd = T_open(oname, O_WRONLY | O_CREAT | O_BINARY | O_TRUNC, S_IREAD | S_IWRITE | S_IEXEC);
if (fd == -1)
return setError("Can't create file");
diff --git a/src/PEImage.h b/src/PEImage.h
index a2009aa..45bc76b 100644
--- a/src/PEImage.h
+++ b/src/PEImage.h
@@ -19,7 +19,7 @@ struct OMFDirEntry;
class PEImage : public LastError
{
public:
- PEImage(const char* iname = 0);
+ PEImage(const TCHAR* iname = 0);
~PEImage();
template<class P> P* DP(int off) const
@@ -56,8 +56,8 @@ public:
return 0;
}
- bool load(const char* iname);
- bool save(const char* oname);
+ bool load(const TCHAR* iname);
+ bool save(const TCHAR* oname);
bool replaceDebugSection (const void* data, int datalen, bool initCV);
bool initCVPtr(bool initDbgDir);
diff --git a/src/cv2pdb.cpp b/src/cv2pdb.cpp
index aa6380c..86e0409 100644
--- a/src/cv2pdb.cpp
+++ b/src/cv2pdb.cpp
@@ -125,10 +125,18 @@ bool CV2PDB::cleanup(bool commit)
return true;
}
-bool CV2PDB::openPDB(const char* pdbname)
+bool CV2PDB::openPDB(const TCHAR* pdbname)
{
+#ifdef UNICODE
+ const wchar_t* pdbnameW = pdbname;
+ char pdbnameA[260]; // = L"c:\\tmp\\aa\\ddoc4.pdb";
+ WideCharToMultiByte(CP_UTF8, 0, pdbname, -1, pdbnameA, 260, 0, 0);
+ // wcstombs (pdbnameA, pdbname, 260);
+#else
+ const char* pdbnameA = pdbname;
wchar_t pdbnameW[260]; // = L"c:\\tmp\\aa\\ddoc4.pdb";
mbstowcs (pdbnameW, pdbname, 260);
+#endif
if (!initMsPdb ())
return setError("cannot load PDB helper DLL");
@@ -142,11 +150,11 @@ bool CV2PDB::openPDB(const char* pdbname)
printf("PDB::QueryPdbImplementationVersion() = %d\n", pdb->QueryPdbImplementationVersion());
#endif
- rsds = (OMFSignatureRSDS *) new char[24 + strlen(pdbname) + 1]; // sizeof(OMFSignatureRSDS) without name
+ rsds = (OMFSignatureRSDS *) new char[24 + strlen(pdbnameA) + 1]; // sizeof(OMFSignatureRSDS) without name
memcpy (rsds->Signature, "RSDS", 4);
pdb->QuerySignature2(&rsds->guid);
rsds->unknown = pdb->QueryAge();
- strcpy(rsds->name, pdbname);
+ strcpy(rsds->name, pdbnameA);
int rc = pdb->CreateDBI("", &dbi);
if (rc <= 0 || !dbi)
@@ -3096,7 +3104,7 @@ bool CV2PDB::addSymbols()
return rc;
}
-bool CV2PDB::writeImage(const char* opath)
+bool CV2PDB::writeImage(const TCHAR* opath)
{
int len = sizeof(*rsds) + strlen((char*)(rsds + 1)) + 1;
if (!img.replaceDebugSection(rsds, len, true))
diff --git a/src/cv2pdb.h b/src/cv2pdb.h
index 1adbe61..03e0b5e 100644
--- a/src/cv2pdb.h
+++ b/src/cv2pdb.h
@@ -28,7 +28,7 @@ public:
~CV2PDB();
bool cleanup(bool commit);
- bool openPDB(const char* pdbname);
+ bool openPDB(const TCHAR* pdbname);
bool setError(const char* msg);
bool createModules();
@@ -152,7 +152,7 @@ public:
bool createSrcLineBitmap();
int getNextSrcLine(int seg, unsigned int off);
- bool writeImage(const char* opath);
+ bool writeImage(const TCHAR* opath);
mspdb::Mod* globalMod();
@@ -163,7 +163,7 @@ public:
bool addDWARFLines();
bool addDWARFPublics();
bool relocateDebugLineInfo();
- bool writeDWARFImage(const char* opath);
+ bool writeDWARFImage(const TCHAR* opath);
bool addDWARFSectionContrib(mspdb::Mod* mod, unsigned long pclo, unsigned long pchi);
bool addDWARFProc(DWARF_InfoData& id, DWARF_CompilationUnit* cu, unsigned char* &locals, unsigned char* end);
diff --git a/src/cv2pdb.vcproj b/src/cv2pdb.vcproj
index bb7e6e7..ea09f64 100644
--- a/src/cv2pdb.vcproj
+++ b/src/cv2pdb.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="9,00"
+ Version="9.00"
Name="cv2pdb"
ProjectGUID="{5E2BD27D-446A-4C99-9829-135F7C000D90}"
RootNamespace="cv2pdb"
@@ -21,7 +21,7 @@
OutputDirectory="..\bin\$(ConfigurationName)"
IntermediateDirectory="..\bin\$(ConfigurationName)\$(ProjectName)"
ConfigurationType="1"
- CharacterSet="2"
+ CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
@@ -69,7 +69,6 @@
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
- Profile="true"
/>
<Tool
Name="VCALinkTool"
@@ -98,7 +97,7 @@
OutputDirectory="..\bin\$(ConfigurationName)"
IntermediateDirectory="..\bin\$(ConfigurationName)\$(ProjectName)"
ConfigurationType="1"
- CharacterSet="2"
+ CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
diff --git a/src/dwarf2pdb.cpp b/src/dwarf2pdb.cpp
index eb325e7..8240627 100644
--- a/src/dwarf2pdb.cpp
+++ b/src/dwarf2pdb.cpp
@@ -250,30 +250,33 @@ struct DWARF_LineState
///////////////////////////////////////////////////////////////////////////////
-long decodeLocation(unsigned char* loc, int &id, int& size)
+long decodeLocation(unsigned char* loc, bool push0, int &id, int& size)
{
unsigned char* p = loc;
- int stackDepth = 0;
+ long stack[8] = {0};
+ int stackDepth = push0 ? 1 : 0;
long data = 0;
+ id = push0 ? S_CONSTANT_V2 : -1;
do
{
int op = *p++;
- id = -1;
+ if(op == 0)
+ break;
size = 0;
switch(op)
{
- case DW_OP_addr: id = S_GDATA_V2; size = 4; data = RD4(p); break;
- case DW_OP_fbreg: id = S_BPREL_V2; data = SLEB128(p); break;
- case DW_OP_const1u: id = S_CONSTANT_V2; size = 1; data = *p; break;
- case DW_OP_const2u: id = S_CONSTANT_V2; size = 2; data = RD2(p); break;
- case DW_OP_const4u: id = S_CONSTANT_V2; size = 4; data = RD4(p); break;
- case DW_OP_const1s: id = S_CONSTANT_V2; size = 1; data = (char)*p; break;
- case DW_OP_const2s: id = S_CONSTANT_V2; size = 2; data = (short)RD2(p); break;
- case DW_OP_const4s: id = S_CONSTANT_V2; size = 4; data = (int)RD4(p); break;
- case DW_OP_constu: id = S_CONSTANT_V2; data = LEB128(p); break;
- case DW_OP_consts: id = S_CONSTANT_V2; data = SLEB128(p); break;
- case DW_OP_plus_uconst: id = S_CONSTANT_V2; data = LEB128(p); break;
+ case DW_OP_addr: id = S_GDATA_V2; size = 4; stack[stackDepth++] = RD4(p); break;
+ case DW_OP_fbreg: id = S_BPREL_V2; stack[stackDepth++] = SLEB128(p); break;
+ case DW_OP_const1u: id = S_CONSTANT_V2; size = 1; stack[stackDepth++] = *p; break;
+ case DW_OP_const2u: id = S_CONSTANT_V2; size = 2; stack[stackDepth++] = RD2(p); break;
+ case DW_OP_const4u: id = S_CONSTANT_V2; size = 4; stack[stackDepth++] = RD4(p); break;
+ case DW_OP_const1s: id = S_CONSTANT_V2; size = 1; stack[stackDepth++] = (char)*p; break;
+ case DW_OP_const2s: id = S_CONSTANT_V2; size = 2; stack[stackDepth++] = (short)RD2(p); break;
+ case DW_OP_const4s: id = S_CONSTANT_V2; size = 4; stack[stackDepth++] = (int)RD4(p); break;
+ case DW_OP_constu: id = S_CONSTANT_V2; stack[stackDepth++] = LEB128(p); break;
+ case DW_OP_consts: id = S_CONSTANT_V2; stack[stackDepth++] = SLEB128(p); break;
+ case DW_OP_plus_uconst: stack[stackDepth-1] += LEB128(p); break;
case DW_OP_lit0: case DW_OP_lit1: case DW_OP_lit2: case DW_OP_lit3:
case DW_OP_lit4: case DW_OP_lit5: case DW_OP_lit6: case DW_OP_lit7:
case DW_OP_lit8: case DW_OP_lit9: case DW_OP_lit10: case DW_OP_lit11:
@@ -283,7 +286,7 @@ long decodeLocation(unsigned char* loc, int &id, int& size)
case DW_OP_lit24: case DW_OP_lit25: case DW_OP_lit26: case DW_OP_lit27:
case DW_OP_lit28: case DW_OP_lit29: case DW_OP_lit30: case DW_OP_lit31:
id = S_CONSTANT_V2;
- data = op - DW_OP_lit0;
+ stack[stackDepth++] = op - DW_OP_lit0;
break;
case DW_OP_reg0: case DW_OP_reg1: case DW_OP_reg2: case DW_OP_reg3:
case DW_OP_reg4: case DW_OP_reg5: case DW_OP_reg6: case DW_OP_reg7:
@@ -318,12 +321,12 @@ long decodeLocation(unsigned char* loc, int &id, int& size)
case DW_OP_deref: break;
case DW_OP_deref_size: size = 1; break;
- case DW_OP_dup: stackDepth++; break;
+ case DW_OP_dup: stack[stackDepth] = stack[stackDepth-1]; stackDepth++; break;
case DW_OP_drop: stackDepth--; break;
- case DW_OP_over: stackDepth++; break;
- case DW_OP_pick: size = 1; stackDepth++; break;
- case DW_OP_swap: break;
- case DW_OP_rot: break;
+ case DW_OP_over: stack[stackDepth] = stack[stackDepth-2]; stackDepth++; break;
+ case DW_OP_pick: size = 1; stack[stackDepth++] = stack[*p]; break;
+ case DW_OP_swap: data = stack[stackDepth-1]; stack[stackDepth-1] = stack[stackDepth-2]; stack[stackDepth-2] = data; break;
+ case DW_OP_rot: data = stack[stackDepth-1]; stack[stackDepth-1] = stack[stackDepth-2]; stack[stackDepth-2] = stack[stackDepth-3]; stack[stackDepth-3] = data; break;
case DW_OP_xderef: stackDepth--; break;
case DW_OP_xderef_size: size = 1; stackDepth--; break;
@@ -336,51 +339,51 @@ long decodeLocation(unsigned char* loc, int &id, int& size)
case DW_OP_bit_piece:
case DW_OP_implicit_value: /* DWARF4 */
case DW_OP_stack_value:
- assert(!"unsupported expression operations");
+ //assert(!"unsupported expression operations");
+ id = -1;
+ return 0;
// unary operations pop and push
- case DW_OP_abs:
- case DW_OP_neg:
- case DW_OP_not:
+ case DW_OP_abs: stack[stackDepth-1] = abs(stack[stackDepth-1]); break;
+ case DW_OP_neg: stack[stackDepth-1] = -stack[stackDepth-1]; break;
+ case DW_OP_not: stack[stackDepth-1] = ~stack[stackDepth-1]; break;
break;
// biary operations pop twice and push
- case DW_OP_and:
- case DW_OP_div:
- case DW_OP_minus:
- case DW_OP_mod:
- case DW_OP_mul:
- case DW_OP_or:
- case DW_OP_plus:
- case DW_OP_shl:
- case DW_OP_shr:
- case DW_OP_shra:
- case DW_OP_xor:
- case DW_OP_eq:
- case DW_OP_ge:
- case DW_OP_gt:
- case DW_OP_le:
- case DW_OP_lt:
- case DW_OP_ne:
- stackDepth--; break;
+ case DW_OP_and: stack[stackDepth-2] = stack[stackDepth-2] & stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_div: stack[stackDepth-2] = stack[stackDepth-2] / stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_minus: stack[stackDepth-2] = stack[stackDepth-2] - stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_mod: stack[stackDepth-2] = stack[stackDepth-2] % stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_mul: stack[stackDepth-2] = stack[stackDepth-2] * stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_or: stack[stackDepth-2] = stack[stackDepth-2] | stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_plus: stack[stackDepth-2] = stack[stackDepth-2] + stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_shl: stack[stackDepth-2] = stack[stackDepth-2] << stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_shr: stack[stackDepth-2] = stack[stackDepth-2] >> stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_shra: stack[stackDepth-2] = stack[stackDepth-2] >> stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_xor: stack[stackDepth-2] = stack[stackDepth-2] ^ stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_eq: stack[stackDepth-2] = stack[stackDepth-2] == stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_ge: stack[stackDepth-2] = stack[stackDepth-2] >= stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_gt: stack[stackDepth-2] = stack[stackDepth-2] > stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_le: stack[stackDepth-2] = stack[stackDepth-2] <= stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_lt: stack[stackDepth-2] = stack[stackDepth-2] < stack[stackDepth-1]; stackDepth--; break;
+ case DW_OP_ne: stack[stackDepth-2] = stack[stackDepth-2] != stack[stackDepth-1]; stackDepth--; break;
+
case DW_OP_bra:
case DW_OP_skip:
size = RD2(p) + 2;
break;
}
- if(id >= 0)
- stackDepth++;
p += size;
}
- while(false); // stackDepth > 0);
+ while(stackDepth > 0);
size = p - loc;
- return data;
+ return stack[0];
}
-long decodeLocation(unsigned long long loc, int &id)
+long decodeLocation(unsigned long long loc, bool push0, int &id)
{
int size;
- return decodeLocation((unsigned char*) &loc, id, size);
+ return decodeLocation((unsigned char*) &loc, push0, id, size);
}
unsigned char* CV2PDB::getDWARFAbbrev(int off, int findcode)
@@ -726,7 +729,7 @@ bool CV2PDB::addDWARFProc(DWARF_InfoData& procid, DWARF_CompilationUnit* cu,
{
if(id.name)
{
- off = decodeLocation(id.location, cvid);
+ off = decodeLocation(id.location, false, cvid);
if(cvid == S_BPREL_V2)
appendStackVar(id.name, getTypeByDWARFOffset(cu, id.type), off + frameOff);
}
@@ -740,7 +743,7 @@ bool CV2PDB::addDWARFProc(DWARF_InfoData& procid, DWARF_CompilationUnit* cu,
case DW_TAG_variable:
if(id.name)
{
- off = decodeLocation(id.location, cvid);
+ off = decodeLocation(id.location, false, cvid);
if(cvid == S_BPREL_V2)
appendStackVar(id.name, getTypeByDWARFOffset(cu, id.type), off + frameOff);
}
@@ -815,7 +818,7 @@ int CV2PDB::addDWARFStructure(DWARF_InfoData& structid, DWARF_CompilationUnit* c
int cvid = -1;
if (id.tag == DW_TAG_member && id.name)
{
- int off = isunion ? 0 : decodeLocation(id.member_location, cvid);
+ int off = isunion ? 0 : decodeLocation(id.member_location, true, cvid);
if(isunion || cvid == S_CONSTANT_V2)
{
checkDWARFTypeAlloc(kMaxNameLen + 100);
@@ -826,7 +829,7 @@ int CV2PDB::addDWARFStructure(DWARF_InfoData& structid, DWARF_CompilationUnit* c
}
else if(id.tag == DW_TAG_inheritance)
{
- int off = decodeLocation(id.member_location, cvid);
+ int off = decodeLocation(id.member_location, true, cvid);
if(cvid == S_CONSTANT_V2)
{
codeview_fieldtype* bc = (codeview_fieldtype*) (dwarfTypes + cbDwarfTypes);
@@ -1253,7 +1256,7 @@ bool CV2PDB::iterateDWARFDebugInfo(int op)
else
{
int cvid;
- segOff = decodeLocation(id.location, cvid);
+ segOff = decodeLocation(id.location, false, cvid);
if(cvid == S_GDATA_V2)
seg = img.findSection(segOff);
if(seg >= 0)
@@ -1691,7 +1694,7 @@ bool CV2PDB::addDWARFPublics()
return true;
}
-bool CV2PDB::writeDWARFImage(const char* opath)
+bool CV2PDB::writeDWARFImage(const TCHAR* opath)
{
int len = sizeof(*rsds) + strlen((char*)(rsds + 1)) + 1;
if (!img.replaceDebugSection(rsds, len, false))
diff --git a/src/main.cpp b/src/main.cpp
index 7ac2972..110589d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,6 +14,32 @@ double
#include "../VERSION"
;
+#ifdef UNICODE
+#define T_toupper towupper
+#define T_getdcwd _wgetdcwd
+#define T_strlen wcslen
+#define T_strcpy wcscpy
+#define T_strcat wcscat
+#define T_strstr wcsstr
+#define T_strtod wcstod
+#define T_strrchr wcsrchr
+#define T_unlink _wremove
+#define T_main wmain
+#define SARG "%S"
+#else
+#define T_toupper toupper
+#define T_getdcwd _getdcwd
+#define T_strlen strlen
+#define T_strcpy strcpy
+#define T_strcat strcat
+#define T_strstr strstr
+#define T_strtod strtod
+#define T_strrchr strrchr
+#define T_unlink unlink
+#define T_main main
+#define SARG "%s"
+#endif
+
void fatal(const char *message, ...)
{
va_list argptr;
@@ -24,18 +50,18 @@ void fatal(const char *message, ...)
exit(1);
}
-void makefullpath(char* pdbname)
+void makefullpath(TCHAR* pdbname)
{
- char* pdbstart = pdbname;
- char fullname[260];
- char* pfullname = fullname;
+ TCHAR* pdbstart = pdbname;
+ TCHAR fullname[260];
+ TCHAR* pfullname = fullname;
int drive = 0;
if (pdbname[0] && pdbname[1] == ':')
{
if (pdbname[2] == '\\' || pdbname[2] == '/')
return;
- drive = toupper (pdbname[0]);
+ drive = T_toupper (pdbname[0]);
pdbname += 2;
}
else
@@ -45,8 +71,8 @@ void makefullpath(char* pdbname)
if (*pdbname != '\\' && *pdbname != '/')
{
- _getdcwd(drive, pfullname, sizeof(fullname) - 2);
- pfullname += strlen(pfullname);
+ T_getdcwd(drive, pfullname, sizeof(fullname)/sizeof(fullname[0]) - 2);
+ pfullname += T_strlen(pfullname);
if (pfullname[-1] != '\\')
*pfullname++ = '\\';
}
@@ -55,42 +81,30 @@ void makefullpath(char* pdbname)
*pfullname++ = 'a' - 1 + drive;
*pfullname++ = ':';
}
- strcpy(pfullname, pdbname);
- strcpy(pdbstart, fullname);
+ T_strcpy(pfullname, pdbname);
+ T_strcpy(pdbstart, fullname);
- for(char*p = pdbstart; *p; p++)
+ for(TCHAR*p = pdbstart; *p; p++)
if (*p == '/')
*p = '\\';
// remove relative parts "./" and "../"
- while (char* p = strstr (pdbstart, "\\.\\"))
- strcpy(p, p + 2);
+ while (TCHAR* p = T_strstr (pdbstart, TEXT("\\.\\")))
+ T_strcpy(p, p + 2);
- while (char* p = strstr (pdbstart, "\\..\\"))
+ while (TCHAR* p = T_strstr (pdbstart, TEXT("\\..\\")))
{
- for (char* q = p - 1; q >= pdbstart; q--)
+ for (TCHAR* q = p - 1; q >= pdbstart; q--)
if (*q == '\\')
{
- strcpy(q, p + 3);
+ T_strcpy(q, p + 3);
break;
}
}
}
-int main(int argc, char** argv)
+int T_main(int argc, TCHAR* argv[])
{
- if (argc < 2)
- {
- printf("Convert DMD CodeView/DWARF debug information to PDB files, Version %g\n", VERSION);
- printf("Copyright (c) 2009-2012 by Rainer Schuetze, All Rights Reserved\n");
- printf("\n");
- printf("License for redistribution is given by the Artistic License 2.0\n");
- printf("see file LICENSE for further details\n");
- printf("\n");
- printf("usage: %s [-Dversion|-C|-n|-sC] <exe-file> [new-exe-file] [pdb-file]\n", argv[0]);
- return -1;
- }
-
PEImage img;
double Dversion = 2.043;
@@ -101,7 +115,7 @@ int main(int argc, char** argv)
if (argv[0][1] == '-')
break;
if (argv[0][1] == 'D')
- Dversion = strtod (argv[0] + 2, 0);
+ Dversion = T_strtod(argv[0] + 2, 0);
else if (argv[0][1] == 'C')
Dversion = 0;
else if (argv[0][1] == 'n')
@@ -109,91 +123,103 @@ int main(int argc, char** argv)
else if (argv[0][1] == 'e')
useTypedefEnum = true;
else if (argv[0][1] == 's' && argv[0][2])
- dotReplacementChar = argv[0][2];
+ dotReplacementChar = (char)argv[0][2];
else
- fatal("unknown option: %s", argv[0]);
+ fatal("unknown option: " SARG, argv[0]);
+ }
+
+ if (argc < 2)
+ {
+ printf("Convert DMD CodeView/DWARF debug information to PDB files, Version %g\n", VERSION);
+ printf("Copyright (c) 2009-2012 by Rainer Schuetze, All Rights Reserved\n");
+ printf("\n");
+ printf("License for redistribution is given by the Artistic License 2.0\n");
+ printf("see file LICENSE for further details\n");
+ printf("\n");
+ printf("usage: " SARG " [-Dversion|-C|-n|-sC] <exe-file> [new-exe-file] [pdb-file]\n", argv[0]);
+ return -1;
}
if (!img.load(argv[1]))
- fatal("%s: %s", argv[1], img.getLastError());
+ fatal(SARG ": %s", argv[1], img.getLastError());
if (img.countCVEntries() == 0 && !img.hasDWARF())
- fatal("%s: no codeview debug entries found", argv[1]);
+ fatal(SARG ": no codeview debug entries found", argv[1]);
CV2PDB cv2pdb(img);
cv2pdb.Dversion = Dversion;
cv2pdb.initLibraries();
- char* outname = argv[1];
+ TCHAR* outname = argv[1];
if (argc > 2 && argv[2][0])
outname = argv[2];
- char pdbname[260];
+ TCHAR pdbname[260];
if (argc > 3)
- strcpy (pdbname, argv[3]);
+ T_strcpy (pdbname, argv[3]);
else
{
- strcpy (pdbname, outname);
- char *pDot = strrchr (pdbname, '.');
- if (!pDot || pDot <= strrchr (pdbname, '/') || pDot <= strrchr (pdbname, '\\'))
- strcat (pdbname, ".pdb");
+ T_strcpy (pdbname, outname);
+ TCHAR *pDot = T_strrchr (pdbname, '.');
+ if (!pDot || pDot <= T_strrchr (pdbname, '/') || pDot <= T_strrchr (pdbname, '\\'))
+ T_strcat (pdbname, TEXT(".pdb"));
else
- strcpy (pDot, ".pdb");
+ T_strcpy (pDot, TEXT(".pdb"));
}
makefullpath(pdbname);
- unlink(pdbname);
+ T_unlink(pdbname);
if(!cv2pdb.openPDB(pdbname))
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if(img.hasDWARF())
{
if(!cv2pdb.relocateDebugLineInfo())
- fatal("%s: %s", argv[1], cv2pdb.getLastError());
+ fatal(SARG ": %s", argv[1], cv2pdb.getLastError());
if(!cv2pdb.createDWARFModules())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if(!cv2pdb.addDWARFTypes())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if(!cv2pdb.addDWARFLines())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if (!cv2pdb.addDWARFPublics())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if (!cv2pdb.writeDWARFImage(outname))
- fatal("%s: %s", outname, cv2pdb.getLastError());
+ fatal(SARG ": %s", outname, cv2pdb.getLastError());
}
else
{
if (!cv2pdb.initSegMap())
- fatal("%s: %s", argv[1], cv2pdb.getLastError());
+ fatal(SARG ": %s", argv[1], cv2pdb.getLastError());
if (!cv2pdb.initGlobalSymbols())
- fatal("%s: %s", argv[1], cv2pdb.getLastError());
+ fatal(SARG ": %s", argv[1], cv2pdb.getLastError());
if (!cv2pdb.initGlobalTypes())
- fatal("%s: %s", argv[1], cv2pdb.getLastError());
+ fatal(SARG ": %s", argv[1], cv2pdb.getLastError());
if (!cv2pdb.createModules())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if (!cv2pdb.addTypes())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if (!cv2pdb.addSymbols())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if (!cv2pdb.addSrcLines())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if (!cv2pdb.addPublics())
- fatal("%s: %s", pdbname, cv2pdb.getLastError());
+ fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
if (!cv2pdb.writeImage(outname))
- fatal("%s: %s", outname, cv2pdb.getLastError());
+ fatal(SARG ": %s", outname, cv2pdb.getLastError());
}
return 0;
diff --git a/src/mspdb.cpp b/src/mspdb.cpp
index 76ec6d7..ee30833 100644
--- a/src/mspdb.cpp
+++ b/src/mspdb.cpp
@@ -93,7 +93,7 @@ bool exitMsPdb()
return true;
}
-mspdb::PDB* CreatePDB(wchar_t* pdbname)
+mspdb::PDB* CreatePDB(const wchar_t* pdbname)
{
if (!initMsPdb ())
return 0;
diff --git a/src/mspdb.h b/src/mspdb.h
index 16209b4..a0abf78 100644
--- a/src/mspdb.h
+++ b/src/mspdb.h
@@ -526,7 +526,7 @@ public: virtual void EnumNameMap_Special::get(char const * *,unsigned long *);
bool initMsPdb();
bool exitMsPdb();
-mspdb::PDB* CreatePDB(wchar_t* pdbname);
+mspdb::PDB* CreatePDB(const wchar_t* pdbname);
extern char* mspdb_dll;