mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 21:03:23 +08:00
[0.2.x] added : dbgio.h/cpp
git-svn-id: https://pykd.svn.codeplex.com/svn@78902 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
e9fa66a877
commit
404b1a0889
87
pykd/win/dbgio.cpp
Normal file
87
pykd/win/dbgio.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "dbgio.h"
|
||||||
|
#include "win/dbgeng.h"
|
||||||
|
#include "win/windbg.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace pykd {
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void dprint( const std::wstring &str, bool dml )
|
||||||
|
{
|
||||||
|
if ( WindbgGlobalSession::isInit() )
|
||||||
|
{
|
||||||
|
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||||
|
|
||||||
|
for ( size_t i = 0; i < str.size() / 100 + 1; ++i )
|
||||||
|
{
|
||||||
|
g_dbgEng->control->ControlledOutputWide(
|
||||||
|
dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL,
|
||||||
|
L"%ws",
|
||||||
|
str.substr( i*100, min( str.size() - i*100, 100 ) ).c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
python::object sys = python::import("sys");
|
||||||
|
sys.attr("stdout").attr("write")( str );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void dprintln( const std::wstring &str, bool dml )
|
||||||
|
{
|
||||||
|
dprint( str + L"\r\n", dml );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void eprint( const std::wstring &str )
|
||||||
|
{
|
||||||
|
if ( WindbgGlobalSession::isInit() )
|
||||||
|
{
|
||||||
|
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||||
|
|
||||||
|
for ( size_t i = 0; i < str.size() / 100 + 1; ++i )
|
||||||
|
{
|
||||||
|
g_dbgEng->control->OutputWide(
|
||||||
|
DEBUG_OUTPUT_ERROR,
|
||||||
|
L"%ws",
|
||||||
|
str.substr( i*100, min( str.size() - i*100, 100 ) ).c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
python::object sys = python::import("sys");
|
||||||
|
sys.attr("stderr").attr("write")( str );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void eprintln( const std::wstring &str )
|
||||||
|
{
|
||||||
|
eprint( str + L"\r\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
std::string dreadline()
|
||||||
|
{
|
||||||
|
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||||
|
|
||||||
|
char str[0x100];
|
||||||
|
ULONG inputSize = 0;
|
||||||
|
|
||||||
|
g_dbgEng->control->Input( str, sizeof(str), &inputSize );
|
||||||
|
|
||||||
|
return std::string( str ) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
} // end pykd namespace
|
49
pykd/win/dbgio.h
Normal file
49
pykd/win/dbgio.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "dbgengine.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
} // end pykd namespace
|
Loading…
Reference in New Issue
Block a user