From e9fa66a877e4eae2972aeed1619f4caf4e82b4e3 Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Fri, 17 Aug 2012 07:54:49 +0000
Subject: [PATCH] [0.2.x] added : removeBp routine

git-svn-id: https://pykd.svn.codeplex.com/svn@78899 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/bpoint.h       |  1 +
 pykd/dbgengine.h    |  2 ++
 pykd/pymod.cpp      |  5 ++++-
 pykd/win/dbgeng.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/pykd/bpoint.h b/pykd/bpoint.h
index 51d50c2..04e698b 100644
--- a/pykd/bpoint.h
+++ b/pykd/bpoint.h
@@ -15,6 +15,7 @@ ULONG setSoftwareBp(ULONG64 offset, BpCallback &callback = BpCallback() );
 ULONG setHardwareBp(ULONG64 offset, ULONG size, ULONG accessType, BpCallback &callback = BpCallback());
 
 
+
 //////////////////////////////////////////////////////////////////////////////////
 //
 //inline BPOINT_ID setSoftwareBp(ULONG64 addr, BpCallback &callback = BpCallback()) {
diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h
index 76e35c2..cc644b5 100644
--- a/pykd/dbgengine.h
+++ b/pykd/dbgengine.h
@@ -64,6 +64,8 @@ void getStackTrace( STACK_FRAME_DESC* frames, ULONG frameCount, ULONG* frameRetu
 
 //breakpoints
 ULONG breakPointSet( ULONG64 offset, bool hardware = false, ULONG size = 0, ULONG accessType = 0 );
+void breakPointRemove( ULONG id );
+void breakPointRemoveAll();
 
 };
 
diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp
index 5c72467..796aa7f 100644
--- a/pykd/pymod.cpp
+++ b/pykd/pymod.cpp
@@ -226,7 +226,10 @@ BOOST_PYTHON_MODULE( pykd )
         "Set software breakpoint on executiont" ) );
     python::def( "setBp", &setHardwareBp, setHardwareBp_( python::args( "offset", "size", "accsessType", "callback" ) ,
         "Set hardware breakpoint" ) );
-
+    python::def( "removeBp", &breakPointRemove,
+        "Remove breapoint by IDs" );
+    python::def( "removeAllBp", &breakPointRemoveAll,
+        "Remove all breapoints" );
 
     python::class_<intBase>( "intBase", "intBase", python::no_init )
         .def( python::init<python::object&>() )
diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp
index b39d00d..da8bc38 100644
--- a/pykd/win/dbgeng.cpp
+++ b/pykd/win/dbgeng.cpp
@@ -829,6 +829,46 @@ ULONG breakPointSet( ULONG64 offset, bool hardware, ULONG size, ULONG accessType
     return breakId;
 }
 
+///////////////////////////////////////////////////////////////////////////////
+
+void breakPointRemove( ULONG id )
+{
+    PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
+
+    IDebugBreakpoint *bp;
+    HRESULT hres = g_dbgEng->control->GetBreakpointById(id, &bp);
+    if (S_OK != hres)
+        throw DbgException("IDebugControl::GetBreakpointById", hres);
+
+    hres = g_dbgEng->control->RemoveBreakpoint(bp);
+    if (S_OK != hres)
+        throw DbgException("IDebugControl::RemoveBreakpoint", hres);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+void breakPointRemoveAll()
+{
+    ULONG numberOfBps;
+    do {
+        HRESULT hres = g_dbgEng->control->GetNumberBreakpoints(&numberOfBps);
+        if (S_OK != hres)
+            throw DbgException("IDebugControl::GetNumberBreakpoints", hres);
+
+        if (!numberOfBps)
+            break;
+
+        IDebugBreakpoint *bp;
+        hres = g_dbgEng->control->GetBreakpointByIndex(0, &bp);
+        if (S_OK != hres)
+            throw DbgException("IDebugControl::GetBreakpointByIndex", hres);
+
+        hres = g_dbgEng->control->RemoveBreakpoint(bp);
+        if (S_OK != hres)
+            throw DbgException("IDebugControl::RemoveBreakpoint", hres);
+
+    } while (numberOfBps);
+}
 
 ///////////////////////////////////////////////////////////////////////////////