added : stackFrame::getSourceLine method

:
This commit is contained in:
ussrhero 2019-04-30 00:12:21 +03:00
parent 877968ca92
commit 89d5c3e5f9
5 changed files with 34 additions and 4 deletions

View File

@ -259,6 +259,20 @@ python::tuple StackFrameAdapter::findSymbol(kdlib::StackFramePtr& frame)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
python::tuple StackFrameAdapter::getSourceLine(kdlib::StackFramePtr& frame)
{
std::wstring fileName;
unsigned long lineno;
do {
AutoRestorePyState pystate;
frame->getSourceLine(fileName, lineno);
} while (false);
return python::make_tuple(fileName, lineno);
}
///////////////////////////////////////////////////////////////////////////////
python::tuple CPUContextAdapter::getRegisterByIndex(unsigned long index) python::tuple CPUContextAdapter::getRegisterByIndex(unsigned long index)
{ {

View File

@ -78,6 +78,8 @@ public:
AutoRestorePyState pystate; AutoRestorePyState pystate;
return frame->isInline(); return frame->isInline();
} }
static python::tuple getSourceLine(kdlib::StackFramePtr& frame);
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -1121,8 +1121,8 @@ void pykd_init()
"this virtual frame of inlined function" ) "this virtual frame of inlined function" )
.def( "findSymbol", StackFrameAdapter::findSymbol, .def( "findSymbol", StackFrameAdapter::findSymbol,
"return symbol for frame's instruction pointer") "return symbol for frame's instruction pointer")
//.def( "getSourceLine", StackFrameAdapter::getSourceLine, .def( "getSourceLine", StackFrameAdapter::getSourceLine,
// "return source line for stack frame's function" ) "return source line for stack frame's function" )
.def( "__str__", StackFrameAdapter::print ); .def( "__str__", StackFrameAdapter::print );
python::class_<CPUContextAdapter>("cpu", "class for CPU context representation" ) python::class_<CPUContextAdapter>("cpu", "class for CPU context representation" )

View File

@ -147,5 +147,4 @@ class ModuleTest( unittest.TestCase ):
def testPrint(self): def testPrint(self):
modAsStr = str(target.module) modAsStr = str(target.module)
pass

View File

@ -87,5 +87,20 @@ class InlineStackTest(unittest.TestCase):
self.assertEqual( expectedStack, realStack[0:4]) self.assertEqual( expectedStack, realStack[0:4])
def testFrameIsInline(self):
self.assertEqual([True, True, False, True],
[fr.isInline() for fr in pykd.getStack(inlineFrames = True)][:4]
)
def testGetSourceLine(self):
expectedStack = ['targetapp.cpp+129', 'targetapp.cpp+144', 'targetapp.cpp+172', 'targetapp.cpp+185']
realStack = []
for frame in pykd.getStack(inlineFrames = True)[:4]:
fileName, lineNo = frame.getSourceLine()
realStack.append("%s+%s" % ( os.path.basename(fileName), lineNo ) )
self.assertEqual( expectedStack, realStack)