From a1f173a1939c0999491a48395325afbcf3a60024 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 23 May 2011 09:23:53 +0000 Subject: [PATCH] [pykd] added : lost dbgbreak.cpp/h files git-svn-id: https://pykd.svn.codeplex.com/svn@65723 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgbreak.cpp | 143 ++++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgbreak.h | 45 +++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 pykd/dbgbreak.cpp create mode 100644 pykd/dbgbreak.h diff --git a/pykd/dbgbreak.cpp b/pykd/dbgbreak.cpp new file mode 100644 index 0000000..2623d28 --- /dev/null +++ b/pykd/dbgbreak.cpp @@ -0,0 +1,143 @@ +#include "stdafx.h" + +#include + +#include "dbgbreak.h" +#include "dbgexcept.h" + +/////////////////////////////////////////////////////////////////////////////// + +dbgBreakpointClass::breakpointMap dbgBreakpointClass::m_breakMap; + +/////////////////////////////////////////////////////////////////////////////// + +HRESULT dbgBreakpointClass::onBreakpointEvnet( IDebugBreakpoint* bp ) +{ + try { + + breakpointMap::iterator it = m_breakMap.find( bp ); + if ( it != m_breakMap.end() ) + return boost::python::extract( it->second->m_callback() ); + + } + catch(...) + {} + + return DEBUG_STATUS_NO_CHANGE; +} + +/////////////////////////////////////////////////////////////////////////////// + +dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset, boost::python::object &callback ) +{ + m_offset = offset; + m_breakpoint = NULL; + m_callback = callback; + + set(); +} + +/////////////////////////////////////////////////////////////////////////////// + +dbgBreakpointClass::~dbgBreakpointClass() +{ + remove(); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +dbgBreakpointClass::set() +{ + HRESULT hres; + + try { + + if ( m_breakpoint ) + return true; + + hres = dbgExt->control->AddBreakpoint( DEBUG_BREAKPOINT_CODE, DEBUG_ANY_ID, &m_breakpoint ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::AddBreakpoint failed" ); + + hres = m_breakpoint->SetOffset( m_offset ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugBreakpoint::SetOffset failed" ); + + hres = m_breakpoint->SetFlags( DEBUG_BREAKPOINT_ENABLED ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugBreakpoint::SetFlags failed" ); + + m_breakMap.insert( std::make_pair( m_breakpoint, this ) ); + + return true; + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + remove(); + + return false; +} + +/////////////////////////////////////////////////////////////////////////////// + +void +dbgBreakpointClass::remove() +{ + if ( m_breakpoint ) + { + dbgExt->control->RemoveBreakpoint( m_breakpoint ); + + breakpointMap::iterator bp = m_breakMap.find( m_breakpoint ); + if ( bp != m_breakMap.end() ) + m_breakMap.erase( bp ); + + m_breakpoint = NULL; + } +} + +/////////////////////////////////////////////////////////////////////////////// + +std::string +dbgBreakpointClass::print() const +{ + HRESULT status = S_OK; + + try + { + if (!m_breakpoint) + return "not set"; + + DEBUG_BREAKPOINT_PARAMETERS params; + status = m_breakpoint->GetParameters(¶ms); + if (FAILED(status)) + throw DbgException("IDebugBreakpoint::GetParameters failed"); + + boost::format fmt("%1$2d %2%%3% %4%:*** "); + fmt % params.Id + % (params.Flags & DEBUG_BREAKPOINT_ENABLED ? 'e' : 'd') + % 'u' + % params.CurrentPassCount; + + return fmt.str(); + } + catch (std::exception & e) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch (...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + return ""; +} + +/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgbreak.h b/pykd/dbgbreak.h new file mode 100644 index 0000000..e3a2381 --- /dev/null +++ b/pykd/dbgbreak.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include "dbgext.h" + +///////////////////////////////////////////////////////////////////////////////// + +class dbgBreakpointClass { + +public: + + dbgBreakpointClass( ULONG64 offset, boost::python::object &callback ); + + ~dbgBreakpointClass(); + + bool + set(); + + void + remove(); + + std::string + print() const; + +private: + + ULONG64 m_offset; + + IDebugBreakpoint *m_breakpoint; + + boost::python::object m_callback; + +private: + + typedef std::map breakpointMap; + static breakpointMap m_breakMap; + +public: + + static HRESULT onBreakpointEvnet( IDebugBreakpoint* bp ); + +}; + +///////////////////////////////////////////////////////////////////////////////// +