Beispiel #1
0
        internal static string ReformatStackTrace(PythonProcess process, string data)
        {
            var lines = new Stack <IEnumerable <string> >();
            var sb    = new StringBuilder();

            using (var reader = new StringReader(data))
            {
                for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
                {
                    lines.Push(SplitReprs(line).ToArray());
                }
            }

            foreach (var line in lines)
            {
                var filename     = line.ElementAtOrDefault(0);
                var lineNumber   = line.ElementAtOrDefault(1);
                var functionName = line.ElementAtOrDefault(2);
                //var text = stackLine.ElementAtOrDefault(3);

                int lineNo;
                if (process != null &&
                    !string.IsNullOrEmpty(filename) &&
                    !string.IsNullOrEmpty(lineNumber) &&
                    int.TryParse(lineNumber, out lineNo) &&
                    !string.IsNullOrEmpty(functionName))
                {
                    functionName = PythonStackFrame.GetQualifiedFunctionName(process, filename, lineNo, functionName);
                }

                if (string.IsNullOrEmpty(functionName))
                {
                    functionName = Strings.DebugUnknownFunctionName;
                }

                if (!string.IsNullOrEmpty(filename))
                {
                    sb.AppendLine(string.IsNullOrEmpty(lineNumber)
                                                ? Strings.DebugPythonExceptionStackTraceFileOnly.FormatUI(filename, functionName)
                                                : Strings.DebugPythonExceptionStackTraceFileAndLineNumber.FormatUI(filename, lineNumber, functionName)
                                  );
                }
                else
                {
                    sb.AppendLine(functionName);
                }
            }

            while (sb.Length > 0 && char.IsWhiteSpace(sb[sb.Length - 1]))
            {
                sb.Length -= 1;
            }

            return(sb.ToString());
        }
Beispiel #2
0
        // Construct a FRAMEINFO for this stack frame with the requested information.
        public void SetFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, out FRAMEINFO frameInfo)
        {
            frameInfo = new FRAMEINFO();

            // The debugger is asking for the formatted name of the function which is displayed in the callstack window.
            // There are several optional parts to this name including the module, argument types and values, and line numbers.
            // The optional information is requested by setting flags in the dwFieldSpec parameter.
            if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME) != 0)
            {
                string funcName = _stackFrame.GetQualifiedFunctionName();
                if (funcName == "<module>")
                {
                    if (PathUtils.IsValidPath(_stackFrame.FileName))
                    {
                        funcName = Strings.DebugFileModule.FormatUI(Path.GetFileNameWithoutExtension(_stackFrame.FileName));
                    }
                    else if (_stackFrame.FileName.EndsWithOrdinal("<string>"))
                    {
                        funcName = Strings.DebugExecEvalFunctionName;
                    }
                    else if (_stackFrame.FileName.EndsWithOrdinal("<stdin>"))
                    {
                        funcName = Strings.DebugReplInputFunctionName;
                    }
                    else
                    {
                        funcName = Strings.DebugFileUnknownCode.FormatUI(_stackFrame.FileName);
                    }
                }
                else if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_MODULE) != 0)
                {
                    funcName = Strings.DebugStackFrameInfoFunctionNameInFileName.FormatUI(
                        funcName,
                        PathUtils.IsValidPath(_stackFrame.FileName)
                            ? Path.GetFileNameWithoutExtension(_stackFrame.FileName)
                            : _stackFrame.FileName
                        );
                    frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_MODULE;
                }

                frameInfo.m_bstrFuncName   = funcName;
                frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_FUNCNAME;

                if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_LINES) != 0)
                {
                    frameInfo.m_bstrFuncName   = Strings.DebugStackFrameFunctionWithLine.FormatUI(funcName, _stackFrame.LineNo);
                    frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_LINES;
                }
            }

            if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_LANGUAGE) != 0)
            {
                switch (_stackFrame.Kind)
                {
                case FrameKind.Python:
                    frameInfo.m_bstrLanguage   = DebuggerLanguageNames.Python;
                    frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_LANGUAGE;
                    break;

                case FrameKind.Django:
                    frameInfo.m_bstrLanguage   = DebuggerLanguageNames.DjangoTemplates;
                    frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_LANGUAGE;
                    break;
                }
            }

            // The debugger is requesting the name of the module for this stack frame.
            if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_MODULE) != 0)
            {
                if (PathUtils.IsValidPath(_stackFrame.FileName))
                {
                    frameInfo.m_bstrModule = Path.GetFileNameWithoutExtension(this._stackFrame.FileName);
                }
                else if (_stackFrame.FileName.EndsWithOrdinal("<string>"))
                {
                    frameInfo.m_bstrModule = Strings.DebugExecEvalModuleName;
                }
                else if (_stackFrame.FileName.EndsWithOrdinal("<stdin>"))
                {
                    frameInfo.m_bstrModule = Strings.DebugReplModuleName;
                }
                else
                {
                    frameInfo.m_bstrModule = Strings.DebugUnknownModuleName;
                }
                frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_MODULE;
            }

            // The debugger is requesting the IDebugStackFrame2 value for this frame info.
            if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FRAME) != 0)
            {
                frameInfo.m_pFrame         = this;
                frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_FRAME;
            }

            // Does this stack frame of symbols loaded?
            if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_DEBUGINFO) != 0)
            {
                frameInfo.m_fHasDebugInfo  = 1;
                frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_DEBUGINFO;
            }

            // Is this frame stale?
            if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_STALECODE) != 0)
            {
                frameInfo.m_fStaleCode     = 0;
                frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_STALECODE;
            }

            // The debugger would like a pointer to the IDebugModule2 that contains this stack frame.
            if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_DEBUG_MODULEP) != 0)
            {
                // TODO: Module

                /*
                 * if (module != null)
                 * {
                 *  AD7Module ad7Module = (AD7Module)module.Client;
                 *  Debug.Assert(ad7Module != null);
                 *  frameInfo.m_pModule = ad7Module;
                 *  frameInfo.m_dwValidFields |= enum_FRAMEINFO_FLAGS.FIF_DEBUG_MODULEP;
                 * }*/
            }
        }