예제 #1
0
 public ReprBuilder(ReprOptions options)
 {
     Options      = options;
     _visitedObjs = new HashSet <ulong>();
 }
예제 #2
0
 private ReprBuilder(ReprBuilder parent)
 {
     Options       = parent.Options;
     _visitedObjs  = parent._visitedObjs;
     _nestingLevel = parent._nestingLevel;
 }
예제 #3
0
        public void OnException(DkmThread thread)
        {
            if (thread.SystemPart == null)
            {
                Debug.Fail("OnException couldn't obtain system thread ID.");
                return;
            }
            var tid = thread.SystemPart.Id;

            var           process = thread.Process;
            PyThreadState tstate  = PyThreadState.GetThreadStates(process).FirstOrDefault(ts => ts.thread_id.Read() == tid);

            if (tstate == null)
            {
                Debug.Fail("OnException couldn't find PyThreadState corresponding to system thread " + tid);
                return;
            }

            var exc_type  = tstate.curexc_type.TryRead();
            var exc_value = tstate.curexc_value.TryRead();

            if (exc_type == null || exc_type.IsNone)
            {
                return;
            }

            var reprOptions = new ReprOptions(process);

            string typeName       = Strings.DebugUnknownExceptionType;
            string additionalInfo = "";

            try {
                var typeObject = exc_type as PyTypeObject;
                if (typeObject != null)
                {
                    var mod = typeObject.__module__;
                    var ver = _process.GetPythonRuntimeInfo().LanguageVersion;
                    if ((mod == "builtins" && ver >= PythonLanguageVersion.V30) ||
                        (mod == "exceptions" && ver < PythonLanguageVersion.V30))
                    {
                        typeName = typeObject.__name__;
                    }
                    else
                    {
                        typeName = mod + "." + typeObject.__name__;
                    }
                }

                var exc = exc_value as PyBaseExceptionObject;
                if (exc != null)
                {
                    var args = exc.args.TryRead();
                    if (args != null)
                    {
                        additionalInfo = args.Repr(reprOptions);
                    }
                }
                else
                {
                    var str = exc_value as IPyBaseStringObject;
                    if (str != null)
                    {
                        additionalInfo = str.ToString();
                    }
                    else if (exc_value != null)
                    {
                        additionalInfo = exc_value.Repr(reprOptions);
                    }
                }
            } catch {
            }

            new RemoteComponent.RaiseExceptionRequest
            {
                ThreadId = thread.UniqueId,
                Name     = typeName,
                AdditionalInformation = Encoding.Unicode.GetBytes(additionalInfo)
            }.SendLower(process);
        }