コード例 #1
0
ファイル: ReprBuilder.cs プロジェクト: PeezoSlug/PTVS
        string ICustomFormatter.Format(string format, object arg, IFormatProvider formatProvider)
        {
            PyObject obj = arg as PyObject;

            if (obj != null)
            {
                ReprBuilder builder = new ReprBuilder(Options);
                builder.AppendRepr(obj);
                return(builder.ToString());
            }
            else if (format == "PY")
            {
                ReprBuilder builder = new ReprBuilder(Options);
                builder.AppendLiteral(arg);
                return(builder.ToString());
            }
            else if (format == "PTR")
            {
                if (Options.Is64Bit)
                {
                    return(string.Format("0x{0:X16}", arg));
                }
                else
                {
                    return(string.Format("0x{0:X8}", arg));
                }
            }
            else
            {
                var formattable = arg as IFormattable;
                if (formattable != null)
                {
                    return(formattable.ToString(format, formatProvider));
                }
                else if (arg != null)
                {
                    return(arg.ToString());
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #2
0
ファイル: ExpressionEvaluator.cs プロジェクト: omnimark/PTVS
            public List<DkmEvaluationResult> GetChildren(ExpressionEvaluator exprEval, DkmEvaluationResult result, DkmInspectionContext inspectionContext) {
                var stackFrame = result.StackFrame;
                var cppEval = new CppExpressionEvaluator(inspectionContext, stackFrame);
                var obj = ValueStore.Read();
                var evalResults = new List<DkmEvaluationResult>();
                var reprOptions = new ReprOptions(inspectionContext);
                var reprBuilder = new ReprBuilder(reprOptions);

                if (DebuggerOptions.ShowCppViewNodes && !HasCppView) {
                    if (CppTypeName == null) {
                        // Try to guess the object's C++ type by looking at function pointers in its PyTypeObject. If they are pointing
                        // into a module for which symbols are available, C++ EE should be able to resolve them into something like
                        // "0x1e120d50 {python33_d.dll!list_dealloc(PyListObject *)}". If we are lucky, one of those functions will have
                        // the first argument declared as a strongly typed pointer, rather than PyObject* or void*.
                        CppTypeName = "PyObject";
                        CppTypeModuleName = null;
                        foreach (string methodField in _methodFields) {
                            var funcPtrEvalResult = cppEval.TryEvaluateObject(null, "PyObject", obj.Address, ".ob_type->" + methodField) as DkmSuccessEvaluationResult;
                            if (funcPtrEvalResult == null || funcPtrEvalResult.Value.IndexOf('{') < 0) {
                                continue;
                            }

                            var match = _cppFirstArgTypeFromFuncPtrRegex.Match(funcPtrEvalResult.Value);
                            string module = match.Groups["module"].Value;
                            string firstArgType = match.Groups["type"].Value;
                            if (firstArgType != "void" && firstArgType != "PyObject" && firstArgType != "_object") {
                                CppTypeName = firstArgType;
                                CppTypeModuleName = module;
                                break;
                            }
                        }
                    }

                    string cppExpr = CppExpressionEvaluator.GetExpressionForObject(CppTypeModuleName, CppTypeName, obj.Address, ",!");
                    var evalResult = DkmIntermediateEvaluationResult.Create(
                        inspectionContext, stackFrame, "[C++ view]", "{C++}" + cppExpr, cppExpr,
                        CppExpressionEvaluator.CppLanguage, stackFrame.Process.GetNativeRuntimeInstance(), null);
                    evalResults.Add(evalResult);
                }

                int i = 0;
                foreach (var child in obj.GetDebugChildren(reprOptions).Take(MaxDebugChildren)) {
                    if (child.Name == null) {
                        reprBuilder.Clear();
                        reprBuilder.AppendFormat("[{0:PY}]", i++);
                        child.Name = reprBuilder.ToString();
                    }

                    DkmEvaluationResult evalResult;
                    if (child.ValueStore is IValueStore<PyObject>) {
                        evalResult = exprEval.CreatePyObjectEvaluationResult(inspectionContext, stackFrame, FullName, child, cppEval);
                    } else {
                        var value = child.ValueStore.Read();
                        reprBuilder.Clear();
                        reprBuilder.AppendLiteral(value);

                        string type = null;
                        if (Process.GetPythonRuntimeInfo().LanguageVersion <= PythonLanguageVersion.V27) {
                            _typeMapping2x.TryGetValue(value.GetType(), out type);
                        }
                        if (type == null) {
                            _typeMapping.TryGetValue(value.GetType(), out type);
                        }

                        var flags = DkmEvaluationResultFlags.ReadOnly;
                        if (value is string) {
                            flags |= DkmEvaluationResultFlags.RawString;
                        }

                        string childFullName = child.Name;
                        if (FullName != null) {
                            if (childFullName.EndsWith("()")) { // len()
                                childFullName = childFullName.Substring(0, childFullName.Length - 2) + "(" + FullName + ")";
                            } else {
                                if (!childFullName.StartsWith("[")) { // [0], ['fob'] etc
                                    childFullName = "." + childFullName;
                                }
                                childFullName = FullName + childFullName;
                            }
                        }

                        evalResult = DkmSuccessEvaluationResult.Create(
                            inspectionContext, stackFrame, child.Name, childFullName, flags, reprBuilder.ToString(), null, type,
                            child.Category, child.AccessType, child.StorageType, child.TypeModifierFlags, null, null, null,
                            new RawEvaluationResult { Value = value });
                    }

                    evalResults.Add(evalResult);
                }

                return evalResults;
            }
コード例 #3
0
ファイル: PyBytesObject.cs プロジェクト: zuokaihuang/PTVS
 public override void Repr(ReprBuilder builder)
 {
     builder.AppendLiteral(new AsciiString(ToBytes(), ToString()));
 }
コード例 #4
0
ファイル: PyBytesObject.cs プロジェクト: zooba/PTVS
 public override void Repr(ReprBuilder builder) {
     builder.AppendLiteral(new AsciiString(ToBytes(), ToString()));
 }
コード例 #5
0
 public override void Repr(ReprBuilder builder)
 {
     builder.AppendLiteral(ToBigInteger());
 }
コード例 #6
0
ファイル: PyLongObject.cs プロジェクト: RussBaz/PTVS
 public override void Repr(ReprBuilder builder) {
     builder.AppendLiteral(ToBigInteger());
 }
コード例 #7
0
ファイル: PyComplexObject.cs プロジェクト: yepeiwen/PTVS
 public override void Repr(ReprBuilder builder)
 {
     builder.AppendLiteral(ToComplex());
 }
コード例 #8
0
ファイル: PyFloatObject.cs プロジェクト: PeezoSlug/PTVS
 public override void Repr(ReprBuilder builder)
 {
     builder.AppendLiteral(ToDouble());
 }
コード例 #9
0
 public override void Repr(ReprBuilder builder)
 {
     builder.AppendLiteral(ToString());
 }
コード例 #10
0
ファイル: PyFloatObject.cs プロジェクト: wenh123/PTVS
 public override void Repr(ReprBuilder builder) {
     builder.AppendLiteral(ToDouble());
 }
コード例 #11
0
ファイル: PyComplexObject.cs プロジェクト: omnimark/PTVS
 public override void Repr(ReprBuilder builder) {
     builder.AppendLiteral(ToComplex());
 }
コード例 #12
0
ファイル: PyUnicodeObject.cs プロジェクト: omnimark/PTVS
 public override void Repr(ReprBuilder builder) {
     builder.AppendLiteral(ToString());
 }