[0.1.x] + DIA: load symbols for executable file

git-svn-id: https://pykd.svn.codeplex.com/svn@74746 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2012-03-06 14:18:38 +00:00 committed by Mikhail I. Izmestev
parent b2d78a7962
commit 6faae9a14c
5 changed files with 160 additions and 3 deletions

View File

@ -89,6 +89,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( getLocals_, getLocals, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBp_, setSoftwareBp, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBp_, setSoftwareBp, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 ); BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 );
BOOST_PYTHON_FUNCTION_OVERLOADS( pyDia_GlobalScope_loadExe, pyDia::GlobalScope::loadExe, 1, 2 );
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadChars, DebugClient::loadChars, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadChars, DebugClient::loadChars, 2, 3 );
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWChars, DebugClient::loadWChars, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWChars, DebugClient::loadWChars, 2, 3 );
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadBytes, DebugClient::loadBytes, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadBytes, DebugClient::loadBytes, 2, 3 );
@ -672,6 +674,8 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb, python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb,
"Open pdb file for querying debug symbols. Return DiaSymbol of global scope"); "Open pdb file for querying debug symbols. Return DiaSymbol of global scope");
python::def( "diaLoadExe", &pyDia::GlobalScope::loadExe, pyDia_GlobalScope_loadExe( python::args( "fileName", "searchPath" ) ,
"Load the debug symbols associated with the executable file. Return DiaSymbol of global scope") );
python::class_<pyDia::Symbol, pyDia::SymbolPtr>( python::class_<pyDia::Symbol, pyDia::SymbolPtr>(
"DiaSymbol", "class wrapper for MS DIA Symbol", python::no_init ) "DiaSymbol", "class wrapper for MS DIA Symbol", python::no_init )

93
pykd/diacallback.h Normal file
View File

@ -0,0 +1,93 @@
//
// DIA load callback
//
#pragma once
namespace pyDia {
class LoadCallback : public IDiaLoadCallback2 {
int m_nRefCount;
public:
LoadCallback() : m_nRefCount(1) {}
ULONG STDMETHODCALLTYPE AddRef() {
m_nRefCount++;
return m_nRefCount;
}
ULONG STDMETHODCALLTYPE Release() {
if ( (--m_nRefCount) == 0 )
delete this;
return m_nRefCount;
}
HRESULT STDMETHODCALLTYPE QueryInterface( REFIID rid, void **ppUnk ) {
if ( ppUnk == NULL )
return E_INVALIDARG;
if (rid == __uuidof( IDiaLoadCallback2 ) )
*ppUnk = (IDiaLoadCallback2 *)this;
else if (rid == __uuidof( IDiaLoadCallback ) )
*ppUnk = (IDiaLoadCallback *)this;
else if (rid == __uuidof( IUnknown ) )
*ppUnk = (IUnknown *)this;
else
*ppUnk = NULL;
if ( *ppUnk != NULL ) {
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
HRESULT STDMETHODCALLTYPE NotifyDebugDir(
BOOL fExecutable,
DWORD cbData,
BYTE data[]
)
{
DBG_UNREFERENCED_PARAMETER(fExecutable);
DBG_UNREFERENCED_PARAMETER(cbData);
DBG_UNREFERENCED_PARAMETER(data);
return S_OK;
}
HRESULT STDMETHODCALLTYPE NotifyOpenDBG(
LPCOLESTR dbgPath,
HRESULT resultCode
)
{
DBG_UNREFERENCED_PARAMETER(dbgPath);
DBG_UNREFERENCED_PARAMETER(resultCode);
return S_OK;
}
HRESULT STDMETHODCALLTYPE NotifyOpenPDB(
LPCOLESTR pdbPath,
HRESULT resultCode
)
{
DBG_UNREFERENCED_PARAMETER(pdbPath);
DBG_UNREFERENCED_PARAMETER(resultCode);
return S_OK;
}
HRESULT STDMETHODCALLTYPE RestrictRegistryAccess() {
return S_OK;
}
HRESULT STDMETHODCALLTYPE RestrictSymbolServerAccess() {
return S_OK;
}
HRESULT STDMETHODCALLTYPE RestrictOriginalPathAccess() {
return S_OK;
}
HRESULT STDMETHODCALLTYPE RestrictReferencePathAccess() {
return S_OK;
}
HRESULT STDMETHODCALLTYPE RestrictDBGAccess() {
return S_OK;
}
HRESULT STDMETHODCALLTYPE RestrictSystemRootAccess() {
return S_OK;
}
};
}

View File

@ -2,6 +2,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "diawrapper.h" #include "diawrapper.h"
#include "diacallback.h"
#include "utils.h" #include "utils.h"
namespace pyDia { namespace pyDia {
@ -386,6 +387,57 @@ GlobalScope::GlobalScope(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
GlobalScopePtr GlobalScope::loadPdb(const std::string &filePath) GlobalScopePtr GlobalScope::loadPdb(const std::string &filePath)
{
class CLoaderFromPdb : public IScopeDataLoader {
public:
CLoaderFromPdb(const std::string &filePath) : m_filePath(filePath) {}
virtual void loadData(IDiaDataSource *_scope) override {
HRESULT hres = _scope->loadDataFromPdb( toWStr(m_filePath) );
if ( S_OK != hres )
throw Exception("Call IDiaDataSource::loadDataFromPdb", hres);
}
private:
const std::string &m_filePath;
} loaderFromPdb(filePath);
return loadImpl(loaderFromPdb);
}
////////////////////////////////////////////////////////////////////////////////
GlobalScopePtr GlobalScope::loadExe(const std::string &filePath, PCSTR searchPath /*= NULL*/)
{
if (!searchPath)
searchPath = "SRV**\\\\symbols\\symbols";
class CLoaderForExe : public IScopeDataLoader {
public:
CLoaderForExe(const std::string &filePath, PCSTR searchPath)
: m_filePath(filePath), m_searchPath(searchPath)
{
}
virtual void loadData(IDiaDataSource *_scope) override {
LoadCallback loadCallback;
HRESULT hres =
_scope->loadDataForExe( toWStr(m_filePath), toWStr(m_searchPath), &loadCallback );
if ( S_OK != hres )
throw Exception("Call IDiaDataSource::loadDataForExe", hres);
}
private:
const std::string &m_filePath;
const std::string m_searchPath;
} loaderForExe(filePath, searchPath);
return loadImpl(loaderForExe);
}
////////////////////////////////////////////////////////////////////////////////
GlobalScopePtr GlobalScope::loadImpl(IScopeDataLoader &ScopeDataLoader)
{ {
DiaDataSourcePtr _scope; DiaDataSourcePtr _scope;
@ -394,9 +446,7 @@ GlobalScopePtr GlobalScope::loadPdb(const std::string &filePath)
if ( S_OK != hres ) if ( S_OK != hres )
throw Exception("Call ::CoCreateInstance", hres); throw Exception("Call ::CoCreateInstance", hres);
hres = _scope->loadDataFromPdb( toWStr(filePath) ); ScopeDataLoader.loadData(_scope);
if ( S_OK != hres )
throw Exception("Call IDiaDataSource::loadDataFromPdb", hres);
DiaSessionPtr _session; DiaSessionPtr _session;
hres = _scope->openSession(&_session); hres = _scope->openSession(&_session);

View File

@ -232,6 +232,7 @@ public:
// GlobalScope factory // GlobalScope factory
static GlobalScopePtr loadPdb(const std::string &filePath); static GlobalScopePtr loadPdb(const std::string &filePath);
static GlobalScopePtr loadExe(const std::string &filePath, PCSTR searchPath = NULL);
// RVA -> Symbol // RVA -> Symbol
python::tuple findByRva( python::tuple findByRva(
@ -253,6 +254,11 @@ public:
SymbolPtr getSymbolById(ULONG symId); SymbolPtr getSymbolById(ULONG symId);
private: private:
interface IScopeDataLoader {
virtual ~IScopeDataLoader() {}
virtual void loadData(IDiaDataSource *_scope) = 0;
};
static GlobalScopePtr loadImpl(IScopeDataLoader &ScopeDataLoader);
GlobalScope( GlobalScope(
__inout DiaDataSourcePtr &_scope, __inout DiaDataSourcePtr &_scope,

View File

@ -543,6 +543,10 @@
RelativePath=".\defctxi386.h" RelativePath=".\defctxi386.h"
> >
</File> </File>
<File
RelativePath=".\diacallback.h"
>
</File>
<File <File
RelativePath=".\diaregs.h" RelativePath=".\diaregs.h"
> >