mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00

[pykd] added: typeException, memoryException and their translation into python git-svn-id: https://pykd.svn.codeplex.com/svn@65714 9b283d60-5439-405e-af05-b73fd8c4d996
120 lines
2.8 KiB
C++
120 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <exception>
|
|
#include <string>
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class DbgException : public std::exception
|
|
{
|
|
public:
|
|
|
|
DbgException( const std::string &desc ) :
|
|
std::exception( desc.c_str() )
|
|
{}
|
|
|
|
const char* getDesc() const {
|
|
return what();
|
|
}
|
|
|
|
|
|
static
|
|
void
|
|
exceptionTranslate(const DbgException &e );
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class TypeException : public DbgException
|
|
{
|
|
public:
|
|
|
|
TypeException() :
|
|
DbgException( "type operation invalid" )
|
|
{}
|
|
|
|
TypeException( const std::string &desc ) :
|
|
DbgException( desc )
|
|
{}
|
|
|
|
static
|
|
void
|
|
exceptionTranslate(const TypeException &e );
|
|
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class IndexException : public DbgException
|
|
{
|
|
public:
|
|
|
|
IndexException() :
|
|
DbgException( "Index out of range" )
|
|
{}
|
|
|
|
static
|
|
void
|
|
translate(const IndexException &e ) {
|
|
PyErr_SetString(PyExc_IndexError, "Index out of range");
|
|
}
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class MemoryException : public DbgException
|
|
{
|
|
public:
|
|
|
|
MemoryException( ULONG64 targetAddr ) :
|
|
m_targetAddress( targetAddr ),
|
|
DbgException( MemoryException::DescMaker( targetAddr, false ).desc() )
|
|
{}
|
|
|
|
MemoryException( ULONG64 targetAddr, bool phyAddr ) :
|
|
m_targetAddress( targetAddr ),
|
|
DbgException( MemoryException::DescMaker( targetAddr, phyAddr ).desc() )
|
|
{}
|
|
|
|
static
|
|
void
|
|
translate( const MemoryException &e );
|
|
|
|
ULONG64
|
|
getAddress() const {
|
|
return m_targetAddress;
|
|
}
|
|
|
|
private:
|
|
|
|
ULONG64 m_targetAddress;
|
|
|
|
class DescMaker {
|
|
public:
|
|
DescMaker( ULONG64 addr, bool phyAddr )
|
|
{
|
|
std::stringstream sstr;
|
|
if ( phyAddr )
|
|
sstr << "Memory exception at 0x" << std::hex << addr << " target physical address";
|
|
else
|
|
sstr << "Memory exception at 0x" << std::hex << addr << " target virtual address";
|
|
m_desc = sstr.str();
|
|
}
|
|
|
|
const std::string&
|
|
desc() const {
|
|
return m_desc;
|
|
}
|
|
|
|
private:
|
|
std::string m_desc;
|
|
};
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
extern PyObject *baseExceptionType;
|
|
extern PyObject *typeExceptionType;
|
|
extern PyObject *memoryExceptionType;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|