added : breakpoint.detach method ( convert strong breakpoint reference

to  weak )
This commit is contained in:
ussrhero 2018-10-03 21:56:19 +03:00
parent c498137a51
commit 3305c6d980
4 changed files with 44 additions and 0 deletions

View File

@ -654,7 +654,36 @@ void Breakpoint::remove()
{
m_breakpoint->remove();
m_breakpoint = 0;
return;
}
throw kdlib::DbgException("Cannot remove breakpoint, it is detached");
}
/////////////////////////////////////////////////////////////////////////////////
Breakpoint* Breakpoint::detach()
{
AutoRestorePyState pystate;
if (m_weakBp)
{
throw kdlib::DbgException("Cannot detach 'weak' breakpoint");
}
if (m_breakpoint)
{
if (m_callback)
{
throw kdlib::DbgException("Cannot detach breakpoint with callback");
}
auto bp = m_breakpoint;
m_breakpoint = 0;
return new Breakpoint(bp);
}
throw kdlib::DbgException("Cannot remove breakpoint, it is detached");
}
/////////////////////////////////////////////////////////////////////////////////

View File

@ -105,6 +105,8 @@ public:
void remove();
Breakpoint* detach();
private:
PyThreadState* m_pystate;

View File

@ -1391,6 +1391,8 @@ void pykd_init()
"Remove breakpoint" )
.def("onHit", &Breakpoint::onHit,
"Breakpoint hit callback")
.def("detach", &Breakpoint::detach, python::return_value_policy<python::manage_new_object>(),
"detach breakpoint")
;
python::class_<kdlib::SyntheticSymbol>(

View File

@ -184,3 +184,14 @@ class BreakpointTest( unittest.TestCase ):
bp = pykd.getBp(0)
self.assertEqual(0x100, bp.getOffset())
def testDoubleRemove(self):
bp = pykd.setBp( self.targetModule.CdeclFunc )
bp.remove()
self.assertRaises( pykd.DbgException, bp.remove )
def testDetach(self):
bp = pykd.setBp( self.targetModule.CdeclFunc ).detach()
self.assertEqual(1, pykd.getNumberBreakpoints())
self.assertRaises(pykd.DbgException, bp.detach )
del bp
self.assertEqual(1, pykd.getNumberBreakpoints())