diff --git a/pykd/pycpucontext.cpp b/pykd/pycpucontext.cpp index f93cfef..9405234 100644 --- a/pykd/pycpucontext.cpp +++ b/pykd/pycpucontext.cpp @@ -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) { diff --git a/pykd/pycpucontext.h b/pykd/pycpucontext.h index dc9b4c2..c77b117 100644 --- a/pykd/pycpucontext.h +++ b/pykd/pycpucontext.h @@ -78,6 +78,8 @@ public: AutoRestorePyState pystate; return frame->isInline(); } + + static python::tuple getSourceLine(kdlib::StackFramePtr& frame); }; ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 0de5f07..7663d02 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -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_("cpu", "class for CPU context representation" ) //.def("__init__", python::make_constructor(CPUContextAdapter::getCPUContext) ) diff --git a/test/scripts/moduletest.py b/test/scripts/moduletest.py index 5759cd0..2dd035f 100644 --- a/test/scripts/moduletest.py +++ b/test/scripts/moduletest.py @@ -147,5 +147,4 @@ class ModuleTest( unittest.TestCase ): def testPrint(self): modAsStr = str(target.module) - pass diff --git a/test/scripts/stacktest.py b/test/scripts/stacktest.py index 03cddf7..b469762 100644 --- a/test/scripts/stacktest.py +++ b/test/scripts/stacktest.py @@ -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)