示例#1
0
        public static DkmInstructionSymbol[] FindSymbols(DkmResolvedDocument resolvedDocument, DkmTextSpan textSpan, string text, out DkmSourcePosition[] symbolLocation)
        {
            var sourceFileId = DkmSourceFileId.Create(resolvedDocument.DocumentName, null, null, null);
            var resultSpan   = new DkmTextSpan(textSpan.StartLine, textSpan.StartLine, 0, 0);

            symbolLocation = new[] { DkmSourcePosition.Create(sourceFileId, resultSpan) };

            var location        = new SourceLocation(resolvedDocument.DocumentName, textSpan.StartLine);
            var encodedLocation = location.Encode();

            return(new[] { DkmCustomInstructionSymbol.Create(resolvedDocument.Module, Guids.PythonRuntimeTypeGuid, encodedLocation, 0, encodedLocation) });
        }
示例#2
0
        public DkmStackWalkFrame[] FilterNextFrame(DkmStackContext stackContext, DkmStackWalkFrame nativeFrame)
        {
            PyFrameObject pythonFrame          = null;
            var           nativeModuleInstance = nativeFrame.ModuleInstance;

            if (nativeModuleInstance == _pyrtInfo.DLLs.DebuggerHelper)
            {
                if (_pyrtInfo.LanguageVersion < PythonLanguageVersion.V36 ||
                    (pythonFrame = PyFrameObject.TryCreate(nativeFrame)) == null)
                {
                    return(DebuggerOptions.ShowNativePythonFrames ? new[] { nativeFrame } : new DkmStackWalkFrame[0]);
                }
            }

            var result = new List <DkmStackWalkFrame>();

            if (pythonFrame == null)
            {
                var stackWalkData = stackContext.GetDataItem <StackWalkContextData>();
                if (stackWalkData == null)
                {
                    stackWalkData = new StackWalkContextData();
                    stackContext.SetDataItem(DkmDataCreationDisposition.CreateNew, stackWalkData);
                }
                bool?wasLastFrameNative = stackWalkData.IsLastFrameNative;

                if (nativeModuleInstance != _pyrtInfo.DLLs.Python && nativeModuleInstance != _pyrtInfo.DLLs.CTypes)
                {
                    stackWalkData.IsLastFrameNative = true;
                    if (wasLastFrameNative == false)
                    {
                        result.Add(DkmStackWalkFrame.Create(nativeFrame.Thread, null, nativeFrame.FrameBase, nativeFrame.FrameSize,
                                                            DkmStackWalkFrameFlags.NonuserCode, Strings.DebugCallStackNativeToPythonTransition, null, null));
                    }
                    else
                    {
                        stackWalkData.IsLastFrameNative = true;
                    }
                    result.Add(nativeFrame);
                    return(result.ToArray());
                }
                else
                {
                    stackWalkData.IsLastFrameNative = false;
                    if (wasLastFrameNative == true)
                    {
                        result.Add(DkmStackWalkFrame.Create(nativeFrame.Thread, null, nativeFrame.FrameBase, nativeFrame.FrameSize,
                                                            DkmStackWalkFrameFlags.NonuserCode, Strings.DebugCallStackPythonToNativeTransition, null, null));
                    }
                }

                pythonFrame = PyFrameObject.TryCreate(nativeFrame);
            }
            if (pythonFrame == null)
            {
                if (DebuggerOptions.ShowNativePythonFrames)
                {
                    result.Add(nativeFrame);
                }
                return(result.ToArray());
            }

            PyCodeObject code = pythonFrame.f_code.Read();
            var          loc  = new SourceLocation(
                code.co_filename.Read().ToStringOrNull(),
                pythonFrame.f_lineno.Read(),
                code.co_name.Read().ToStringOrNull(),
                nativeFrame.InstructionAddress as DkmNativeInstructionAddress);

            var pythonRuntime         = _process.GetPythonRuntimeInstance();
            var pythonModuleInstances = pythonRuntime.GetModuleInstances().OfType <DkmCustomModuleInstance>();
            var pyModuleInstance      = pythonModuleInstances.Where(m => m.FullName == loc.FileName).FirstOrDefault();

            if (pyModuleInstance == null)
            {
                pyModuleInstance = pythonModuleInstances.Single(m => m.Module.Id.Mvid == Guids.UnknownPythonModuleGuid);
            }

            var encodedLocation = loc.Encode();
            var instrAddr       = DkmCustomInstructionAddress.Create(pythonRuntime, pyModuleInstance, encodedLocation, 0, encodedLocation, null);
            var frame           = DkmStackWalkFrame.Create(
                nativeFrame.Thread,
                instrAddr,
                nativeFrame.FrameBase,
                nativeFrame.FrameSize,
                DkmStackWalkFrameFlags.None,
                null,
                nativeFrame.Registers,
                nativeFrame.Annotations);

            result.Add(frame);

            if (DebuggerOptions.ShowNativePythonFrames)
            {
                result.Add(nativeFrame);
            }
            return(result.ToArray());
        }