From dd2882c90682885dea946a6e527645b4b237da99 Mon Sep 17 00:00:00 2001 From: sagitario Date: Mon, 18 Jun 2012 17:53:58 +0000 Subject: v0.25 * new option -p allows to specify the embedded PDB reference in the binary * added support for VS2012 --- CHANGES | 4 +++ VERSION | 2 +- src/cv2pdb.cpp | 13 +++---- src/cv2pdb.h | 2 +- src/main.cpp | 7 ++-- src/mspdb.cpp | 20 +++++++++-- src/mspdb.h | 108 ++++++++++++++++++++++++++++++++++++++++----------------- test/cvtest.d | 7 ++++ 8 files changed, 119 insertions(+), 44 deletions(-) diff --git a/CHANGES b/CHANGES index 7acfa25..c5ee8ce 100644 --- a/CHANGES +++ b/CHANGES @@ -169,3 +169,7 @@ unreleased Version 0.22 * supports unicode characters in file names * improve interpretation of DWARF location expression +2012-06-18 Version 0.25 + + * new option -p allows to specify the embedded PDB reference in the binary + * added support for VS2012 diff --git a/VERSION b/VERSION index d57b67e..d4e76c1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -VERSION = 0.24 +VERSION = 0.25 diff --git a/src/cv2pdb.cpp b/src/cv2pdb.cpp index 86e0409..1bbff16 100644 --- a/src/cv2pdb.cpp +++ b/src/cv2pdb.cpp @@ -125,15 +125,15 @@ bool CV2PDB::cleanup(bool commit) return true; } -bool CV2PDB::openPDB(const TCHAR* pdbname) +bool CV2PDB::openPDB(const TCHAR* pdbname, const TCHAR* pdbref) { #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); + WideCharToMultiByte(CP_UTF8, 0, pdbref ? pdbref : pdbname, -1, pdbnameA, 260, 0, 0); // wcstombs (pdbnameA, pdbname, 260); #else - const char* pdbnameA = pdbname; + const char* pdbnameA = pdbref ? pdbref : pdbname; wchar_t pdbnameW[260]; // = L"c:\\tmp\\aa\\ddoc4.pdb"; mbstowcs (pdbnameW, pdbname, 260); #endif @@ -3045,9 +3045,10 @@ bool CV2PDB::writeSymbols(mspdb::Mod* mod, DWORD* data, int databytes, int prefi data[3] = 1; int rc = mod->AddSymbols((BYTE*) data, ((databytes + 3) / 4 + prefix) * 4); if (rc <= 0) - return setError(mspdb::DBI::isVS10 - ? "cannot add symbols to module, probably msobj100.dll missing" - : "cannot add symbols to module, probably msobj80.dll missing"); + return setError( + mspdb::vsVersion == 10 ? "cannot add symbols to module, probably msobj100.dll missing" + : mspdb::vsVersion == 11 ? "cannot add symbols to module, probably msobj110.dll missing" + : "cannot add symbols to module, probably msobj80.dll missing"); return true; } diff --git a/src/cv2pdb.h b/src/cv2pdb.h index 03e0b5e..efdf4fc 100644 --- a/src/cv2pdb.h +++ b/src/cv2pdb.h @@ -28,7 +28,7 @@ public: ~CV2PDB(); bool cleanup(bool commit); - bool openPDB(const TCHAR* pdbname); + bool openPDB(const TCHAR* pdbname, const TCHAR* pdbref); bool setError(const char* msg); bool createModules(); diff --git a/src/main.cpp b/src/main.cpp index 110589d..8c23cf3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -107,6 +107,7 @@ int T_main(int argc, TCHAR* argv[]) { PEImage img; double Dversion = 2.043; + const TCHAR* pdbref = 0; while (argc > 1 && argv[1][0] == '-') { @@ -124,6 +125,8 @@ int T_main(int argc, TCHAR* argv[]) useTypedefEnum = true; else if (argv[0][1] == 's' && argv[0][2]) dotReplacementChar = (char)argv[0][2]; + else if (argv[0][1] == 'p' && argv[0][2]) + pdbref = argv[0] + 2; else fatal("unknown option: " SARG, argv[0]); } @@ -136,7 +139,7 @@ int T_main(int argc, TCHAR* argv[]) 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] [new-exe-file] [pdb-file]\n", argv[0]); + printf("usage: " SARG " [-Dversion|-C|-n|-e|-sC|-pembedded-pdb] [new-exe-file] [pdb-file]\n", argv[0]); return -1; } @@ -169,7 +172,7 @@ int T_main(int argc, TCHAR* argv[]) T_unlink(pdbname); - if(!cv2pdb.openPDB(pdbname)) + if(!cv2pdb.openPDB(pdbname, pdbref)) fatal(SARG ": %s", pdbname, cv2pdb.getLastError()); if(img.hasDWARF()) diff --git a/src/mspdb.cpp b/src/mspdb.cpp index ee30833..3602ccd 100644 --- a/src/mspdb.cpp +++ b/src/mspdb.cpp @@ -15,8 +15,9 @@ mspdb::fnPDBOpen2W *pPDBOpen2W; char* mspdb80_dll = "mspdb80.dll"; char* mspdb100_dll = "mspdb100.dll"; +char* mspdb110_dll = "mspdb110.dll"; -bool mspdb::DBI::isVS10 = false; +int mspdb::vsVersion = 8; bool getInstallDir(const char* version, char* installDir, DWORD size) { @@ -51,6 +52,7 @@ bool initMsPdb() if (!modMsPdb) modMsPdb = LoadLibraryA(mspdb80_dll); +#if 1 if (!modMsPdb) tryLoadMsPdb("VisualStudio\\9.0", mspdb80_dll); if (!modMsPdb) @@ -59,6 +61,7 @@ bool initMsPdb() tryLoadMsPdb("VCExpress\\9.0", mspdb80_dll); if (!modMsPdb) tryLoadMsPdb("VCExpress\\8.0", mspdb80_dll); +#endif #if 1 if (!modMsPdb) @@ -69,7 +72,20 @@ bool initMsPdb() if (!modMsPdb) tryLoadMsPdb("VCExpress\\10.0", mspdb100_dll); if (modMsPdb) - mspdb::DBI::isVS10 = true; + mspdb::vsVersion = 10; + } +#endif + +#if 1 + if (!modMsPdb) + { + modMsPdb = LoadLibraryA(mspdb110_dll); + if (!modMsPdb) + tryLoadMsPdb("VisualStudio\\11.0", mspdb110_dll); + if (!modMsPdb) + tryLoadMsPdb("VCExpress\\11.0", mspdb110_dll); + if (modMsPdb) + mspdb::vsVersion = 11; } #endif diff --git a/src/mspdb.h b/src/mspdb.h index a0abf78..9c48342 100644 --- a/src/mspdb.h +++ b/src/mspdb.h @@ -33,6 +33,7 @@ struct Mod; struct StreamCached; struct GSI; struct TPI; +struct IPI; struct NameMap; struct EnumNameMap; @@ -51,6 +52,9 @@ struct EnumNameMap; #define EnumNameMap2 EnumNameMap struct DBI; + +extern int vsVersion; + /* #define DBICommon DBI #define DBI2 DBI @@ -198,35 +202,76 @@ public: virtual void MRECmp::structIsBoring(unsigned long); typedef int __cdecl fnPDBOpen2W(unsigned short const *path,char const *mode,long *p, unsigned short *ext,unsigned int flags,struct PDB **pPDB); -struct PDB { -public: static int __cdecl PDBCommon::Open2W(unsigned short const *path,char const *mode,long *p,unsigned short *ext,unsigned int flags,struct PDB **pPDB); - -public: virtual unsigned long PDB::QueryInterfaceVersion(void); -public: virtual unsigned long PDB::QueryImplementationVersion(void); -public: virtual long PDBCommon::QueryLastError(char * const); -public: virtual char * PDB::QueryPDBName(char * const); -public: virtual unsigned long PDB::QuerySignature(void); -public: virtual unsigned long PDB::QueryAge(void); -public: virtual int PDB::CreateDBI(char const *,struct DBI * *); -public: virtual int PDB::OpenDBI(char const *,char const *,struct DBI * *); -public: virtual int PDB::OpenTpi(char const *,struct TPI * *); -public: virtual int PDB::Commit(void); -public: virtual int PDB::Close(void); -public: virtual int PDBCommon::OpenStreamW(unsigned short const *,struct Stream * *); -public: virtual int PDB::GetEnumStreamNameMap(struct Enum * *); -public: virtual int PDB::GetRawBytes(int (__cdecl*)(void const *,long)); -public: virtual unsigned long PDB::QueryPdbImplementationVersion(void); -public: virtual int PDB::OpenDBIEx(char const *,char const *,struct DBI * *,int (__stdcall*)(struct _tagSEARCHDEBUGINFO *)); -public: virtual int PDBCommon::CopyTo(char const *,unsigned long,unsigned long); -public: virtual int PDB::OpenSrc(struct Src * *); -public: virtual long PDB::QueryLastErrorExW(unsigned short *,unsigned int); -public: virtual unsigned short * PDB::QueryPDBNameExW(unsigned short *,unsigned int); -public: virtual int PDB::QuerySignature2(struct _GUID *); -public: virtual int PDBCommon::CopyToW(unsigned short const *,unsigned long,unsigned long); -public: virtual int PDB::fIsSZPDB(void)const ; -public: virtual int PDB::containsW(unsigned short const *,unsigned long *); -public: virtual int PDB::CopyToW2(unsigned short const *,unsigned long,int (__cdecl*(__cdecl*)(void *,enum PCC))(void),void *); -public: virtual int PDB::OpenStreamEx(char const *,char const *,struct Stream * *); +struct PDB_part1 { +public: virtual unsigned long QueryInterfaceVersion(void); +public: virtual unsigned long QueryImplementationVersion(void); +public: virtual long QueryLastError(char * const); +public: virtual char * QueryPDBName(char * const); +public: virtual unsigned long QuerySignature(void); +public: virtual unsigned long QueryAge(void); +public: virtual int CreateDBI(char const *,struct DBI * *); +public: virtual int OpenDBI(char const *,char const *,struct DBI * *); +public: virtual int OpenTpi(char const *,struct TPI * *); +}; + +struct PDB_part_vs11 : public PDB_part1 { +public: virtual int OpenIpi(char const *,struct IPI * *); // VS11 +}; + +template +struct PDB_part2 : public BASE { +public: virtual int Commit(void); +public: virtual int Close(void); +public: virtual int OpenStreamW(unsigned short const *,struct Stream * *); +public: virtual int GetEnumStreamNameMap(struct Enum * *); +public: virtual int GetRawBytes(int (__cdecl*)(void const *,long)); +public: virtual unsigned long QueryPdbImplementationVersion(void); +public: virtual int OpenDBIEx(char const *,char const *,struct DBI * *,int (__stdcall*)(struct _tagSEARCHDEBUGINFO *)); +public: virtual int CopyTo(char const *,unsigned long,unsigned long); +public: virtual int OpenSrc(struct Src * *); +public: virtual long QueryLastErrorExW(unsigned short *,unsigned int); +public: virtual unsigned short * QueryPDBNameExW(unsigned short *,unsigned int); +public: virtual int QuerySignature2(struct _GUID *); +public: virtual int CopyToW(unsigned short const *,unsigned long,unsigned long); +public: virtual int fIsSZPDB(void)const ; +public: virtual int containsW(unsigned short const *,unsigned long *); +public: virtual int CopyToW2(unsigned short const *,unsigned long,int (__cdecl*(__cdecl*)(void *,enum PCC))(void),void *); +public: virtual int OpenStreamEx(char const *,char const *,struct Stream * *); +}; + +struct PDB_VS10 : public PDB_part2 {}; +struct PDB_VS11 : public PDB_part2 {}; + +struct PDB +{ + PDB_VS10 vs10; + +public: + static int __cdecl Open2W(unsigned short const *path,char const *mode,long *p,unsigned short *ext,unsigned int flags,struct PDB **pPDB); + + unsigned long QueryAge() { return vs10.QueryAge(); } + int CreateDBI(char const *n,struct DBI * *pdbi) { return vs10.CreateDBI(n, pdbi); } + int OpenTpi(char const *n,struct TPI * *ptpi) { return vs10.OpenTpi(n, ptpi); } + long QueryLastError(char * const lastErr) { return vs10.QueryLastError(lastErr); } + + int Commit() + { + if(vsVersion >= 11) + return ((PDB_VS11*)&vs10)->Commit(); + return vs10.Commit(); + } + int Close() + { + if(vsVersion >= 11) + return ((PDB_VS11*)&vs10)->Close(); + return vs10.Close(); + } + int QuerySignature2(struct _GUID *guid) + { + if(vsVersion >= 11) + return ((PDB_VS11*)&vs10)->QuerySignature2(guid); + return vs10.QuerySignature2(guid); + } }; struct Src { @@ -414,7 +459,6 @@ struct DBI_VS10 : public DBI_BASE {}; struct DBI { - static bool isVS10; DBI_VS9 vs9; unsigned long QueryImplementationVersion() { return vs9.QueryImplementationVersion(); } @@ -425,13 +469,13 @@ struct DBI int AddPublic2(char const *name,unsigned short sec,long off,unsigned long type) { - if(isVS10) + if(vsVersion >= 10) return ((DBI_VS10*) &vs9)->AddPublic2(name, sec, off, type); return vs9.AddPublic2(name, sec, off, type); } void SetMachineType(unsigned short type) { - if(isVS10) + if(vsVersion >= 10) return ((DBI_VS10*) &vs9)->SetMachineType(type); return vs9.SetMachineType(type); } diff --git a/test/cvtest.d b/test/cvtest.d index 5b5d233..73394ee 100644 --- a/test/cvtest.d +++ b/test/cvtest.d @@ -33,6 +33,12 @@ enum enum_name E_NOTIMPL = cast(int)0x80004001, }; +enum derived_enum : ushort +{ + kDerived1, + kDerived2 +} + // field type LF_MEMBER_V1 class class_member { @@ -286,6 +292,7 @@ alias int Action; Action convertEnum() { + derived_enum direvedEnum = derived_enum.kDerived2; return Accept; } -- cgit v0.12