pykd/pykd/win/dbgio.h
SND\kernelnet_cp 080b705c5a [0.2.x] added : dbgCommand routine
git-svn-id: https://pykd.svn.codeplex.com/svn@80216 9b283d60-5439-405e-af05-b73fd8c4d996
2017-11-08 17:42:50 +04:00

121 lines
2.3 KiB
C++

#pragma once
#include <dbgeng.h>
#include "dbgengine.h"
#include "dbgexcept.h"
namespace pykd {
///////////////////////////////////////////////////////////////////////////////
class DbgOut {
public:
void
write( const std::wstring &str ) {
dprint( str );
}
};
///////////////////////////////////////////////////////////////////////////////
class DbgErr {
public:
void
write( const std::wstring &str )
{
eprint( str );
}
};
///////////////////////////////////////////////////////////////////////////////
class DbgIn {
public:
std::string
readline() {
return dreadline();
}
};
///////////////////////////////////////////////////////////////////////////////
class OutputReader : public IDebugOutputCallbacks, private boost::noncopyable {
public:
explicit OutputReader( IDebugClient4 *client )
{
HRESULT hres;
m_client = client;
hres = m_client->GetOutputCallbacks( &m_previousCallback );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient::GetOutputCallbacks failed" );
hres = m_client->SetOutputCallbacks( this );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient::GetOutputCallbacks failed" );
}
~OutputReader()
{
m_client->SetOutputCallbacks( m_previousCallback );
}
const std::string&
Line() const {
return m_readLine;
}
private:
// IUnknown.
STDMETHOD(QueryInterface)(
__in REFIID InterfaceId,
__out PVOID* Interface ) {
return E_NOINTERFACE;
}
STDMETHOD_(ULONG, AddRef)() {
return 1L;
}
STDMETHOD_(ULONG, Release)() {
return 0L;
}
STDMETHOD(Output)(
__in ULONG Mask,
__in PCSTR Text )
{
if ( Mask == DEBUG_OUTPUT_NORMAL )
{
m_readLine += std::string( Text );
}
return S_OK;
}
private:
std::string m_readLine;
CComPtr<IDebugOutputCallbacks> m_previousCallback;
CComPtr<IDebugClient4> m_client;
};
///////////////////////////////////////////////////////////////////////////////
} // end pykd namespace