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)
{

View File

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

View File

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

View File

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

View File

@ -87,5 +87,20 @@ class InlineStackTest(unittest.TestCase):
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)