[pygccxml-commit] SF.net SVN: pygccxml: [1249] pygccxml_dev/pygccxml/parser
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-02-20 12:57:43
|
Revision: 1249 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1249&view=rev Author: roman_yakovenko Date: 2008-02-20 04:57:47 -0800 (Wed, 20 Feb 2008) Log Message: ----------- auto detect of msdiaxx.dll location Modified Paths: -------------- pygccxml_dev/pygccxml/parser/msdia_details.py pygccxml_dev/pygccxml/parser/pdb_reader.py Modified: pygccxml_dev/pygccxml/parser/msdia_details.py =================================================================== --- pygccxml_dev/pygccxml/parser/msdia_details.py 2008-02-20 08:03:33 UTC (rev 1248) +++ pygccxml_dev/pygccxml/parser/msdia_details.py 2008-02-20 12:57:47 UTC (rev 1249) @@ -1,13 +1,73 @@ -import getpass +import os import comtypes import comtypes.client +import _winreg as win_registry +from distutils import msvccompiler -msdia_path = None -if 'root' == getpass.getuser(): - msdia_path = r'C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\msdia90.dll' +class msdia_searcher_t: + def __init__( self ): + self.root_reg_key = win_registry.HKEY_LOCAL_MACHINE + + def find_path( self ): + vss_installed = self.__get_installed_vs_dirs() + msdia_dlls = self.__get_msdia_dll_paths( vss_installed ) + #D:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\ + #D:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\Debugger\msdia71.dll + #C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\msdia90.dll + if 1 == len(msdia_dlls): + return msdia_dlls[0] + else: + #TODO find the highest version and use it. + pass + + def __get_msdia_dll_paths( self, vss_installed ): + msdia_dlls = [] + for vs in vss_installed: + vs = os.path.split( vs )[0] + debug_dir = os.path.join( vs, 'Packages', 'Debugger' ) + files = filter( lambda f: f.startswith( 'msdia' ) and f.endswith( '.dll' ) + , os.listdir( debug_dir ) ) + if not files: + continue + msdia_dlls.extend([ os.path.join( debug_dir, f ) for f in files ]) + if not msdia_dlls: + raise RuntimeError( 'pygccxml unable to find out msdiaXX.dll location' ) + return msdia_dlls + + def __get_installed_vs_dirs( self ): + vs_reg_path = 'Software\Microsoft\VisualStudio' + vss = self.read_keys( self.root_reg_key, vs_reg_path ) + vs_installed_and_exist = [] + + for vs_installed in vss: + values = self.read_values( self.root_reg_key, vs_reg_path + '\\' + vs_installed ) + try: + vs_installed_and_exist.append( os.path.realpath( values['installdir'] ) ) + except KeyError: + pass + + if not vs_installed_and_exist: + raise RuntimeError( 'pygccxml unable to find out a Visual Studio installation directory' ) + return vs_installed_and_exist -msdia = comtypes.client.GetModule( msdia_path ) + + def read_keys(self, base, key): + return msvccompiler.read_keys(base, key) + def read_values(self, base, key): + return msvccompiler.read_values(base, key) + +msdia_path = msdia_searcher_t().find_path() + +comtypes_client_gen_dir = comtypes.client.gen_dir +try: + comtypes.client.gen_dir = None + msdia = comtypes.client.GetModule( msdia_path ) +finally: + comtypes.client.gen_dir = comtypes_client_gen_dir + +#Adding code, that was not generated for some reason. + class UdtKind: UdtStruct, UdtClass, UdtUnion = ( 0, 1, 2 ) @@ -29,21 +89,3 @@ nsCaseInRegularExpression = nsfRegularExpression | nsfCaseInsensitive msdia.NameSearchOptions = NameSearchOptions - - -# -#from distutils import ccompiler -#from distutils import msvccompiler -# -#if 'msvc' == ccompiler.get_default_compiler(): -# cc = msvccompiler.MSVCCompiler() -# cc.initialize() -# generator = 'NMake Makefiles' -# native_build = '"%s" /A all' % cc.find_exe( 'nmake.exe' ) -# configure_environment_script = cc.find_exe( 'vsvars32.bat' ) -# if not configure_environment_script: -# configure_environment_script = cc.find_exe( 'vcvars32.bat' ) -# cl_mapping = { 6.0 : "msvc6", 7.0 : "msvc7", 7.1 : "msvc71", 8.0 : "msvc8" } -# compiler = cl_mapping[ msvccompiler.get_build_version() ] -#else: -# raise RuntimeError( "Unable to find out MSDIA dll location") Modified: pygccxml_dev/pygccxml/parser/pdb_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/pdb_reader.py 2008-02-20 08:03:33 UTC (rev 1248) +++ pygccxml_dev/pygccxml/parser/pdb_reader.py 2008-02-20 12:57:47 UTC (rev 1249) @@ -5,7 +5,8 @@ import comtypes.client from msdia_details import msdia -sys.path.append( r'C:\dev\language-binding\pygccxml_dev' ) +sys.path.append( r'../..' ) +#sys.path.append( r'C:\dev\language-binding\pygccxml_dev' ) from pygccxml import utils from pygccxml import declarations @@ -36,14 +37,6 @@ continue print ' value %s(%d): ' % ( v.name, v.value ) -def print_nss( smb, offset ): - symbols = smb.findChildren( msdia.SymTagUDT, None, 0 ) - for internal_smb in iter( symbols ): - internal_smb = ctypes.cast( internal_smb, ctypes.POINTER( msdia.IDiaSymbol ) ) - if internal_smb.classParentId == smb.symIndexId: - print ' ' * offset, internal_smb.name - print_nss( internal_smb, offset + 1 ) - def print_files( session ): files = iter( session.findFile( None, '', 0 ) ) for f in files: @@ -67,6 +60,11 @@ def read(self): self.__populate_scopes() + files = iter( self.__dia_session.findFile( None, '', 0 ) ) + for f in files: + f = ctypes.cast( f, ctypes.POINTER(msdia.IDiaSourceFile) ) + print 'File: ', f.fileName + @property def dia_global_scope(self): return self.__dia_session.globalScope @@ -141,5 +139,6 @@ if __name__ == '__main__': control_pdb = r'C:\dev\produce_pdb\Debug\produce_pdb.pdb' + control_pdb = r'xxx.pdb' reader = pdb_reader_t( control_pdb ) - reader.read() \ No newline at end of file + reader.read() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |