Exemplo n.º 1
0
        public AsVariable(IDebugProperty3 debugProperty)
        {
            int hr = VSConstants.S_OK;

            DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1];
            hr = debugProperty.GetPropertyInfo(
                enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ALL,
                100, //dwRadix
                10000, //dwTimeout
                new IDebugReference2[] { },
                0,
                propertyInfo);

            if(hr != VSConstants.S_OK)
            {
                throw new Exception("AsVariable : IDebugProperty3.GetPropertyInfo failed");
            }

            debugPropertyInfo_ = propertyInfo[0];
        }
        public int DisplayValue(uint ownerHwnd, uint visualizerId, IDebugProperty3 debugProperty)
        {
            DEBUG_PROPERTY_INFO[] rawValue = new DEBUG_PROPERTY_INFO[1];
            debugProperty.GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW, 10, 10000, null, 0, rawValue);

            //IEnumDebugPropertyInfo2 propInfo;
            //Guid filter = Guid.Empty;
            //int enumResult = debugProperty.EnumChildren(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW, 10, ref filter, enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_ALL, null, 10000, out propInfo);

            //uint bufferLength;
            //debugProperty.GetStringCharLength(out bufferLength);

            //ushort[] buffer = new ushort[bufferLength];
            //uint fetched;
            //debugProperty.GetStringChars(bufferLength, buffer, out fetched);

            DkmSuccessEvaluationResult dkmEvalResult = DkmSuccessEvaluationResult.ExtractFromProperty(debugProperty);

            //DkmInspectionContext inspectionContext = DkmInspectionContext.Create(
            //        dkmEvalResult.InspectionSession,
            //        dkmEvalResult.RuntimeInstance,
            //        dkmEvalResult.InspectionContext.Thread,
            //        1000,
            //        DkmEvaluationFlags.None,
            //        DkmFuncEvalFlags.None,
            //        10,
            //        dkmEvalResult.InspectionContext.Language,
            //        null);

            try
            {
                PointCloudVisualizerControl.Instance.AddItem(dkmEvalResult.FullName, parseMembers(dkmEvalResult));
            }
            catch (Exception e)
            {
                Debug.Fail("Visualization failed: " + e.Message);
                return(e.HResult);
            }

            return(VSConstants.S_OK);
        }
Exemplo n.º 3
0
        public int DisplayValue(uint ownerHwnd, uint visualizerId, IDebugProperty3 debugProperty)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1];
                debugProperty.GetPropertyInfo(
                    enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_STANDARD |
                    enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME |
                    enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP |
                    enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW,
                    10 /* Radix */,
                    10000 /* Eval Timeout */,
                    new IDebugReference2[] { },
                    0,
                    propertyInfo);

                DebugValue debugValue = new DebugValue();
                debugValue.visualizerId = visualizerId;

                int index = propertyInfo[0].bstrType.IndexOf(" {");
                if (index != -1)
                {
                    propertyInfo[0].bstrType = propertyInfo[0].bstrType.Remove(index);
                }
                bool isPointer   = IsEndsWith(propertyInfo[0].bstrType, "*") || IsEndsWith(propertyInfo[0].bstrType, "* const");
                bool isReference = IsEndsWith(propertyInfo[0].bstrType, "&");

                string variableName = propertyInfo[0].bstrName;
                if (propertyInfo[0].bstrFullName != propertyInfo[0].bstrName)
                {
                    variableName = Regex.Match(propertyInfo[0].bstrFullName, @"^[^$.-]*").Value + "..." + variableName;
                }
                debugValue.variableName = Regex.Replace(variableName, @"[""'\/ ]", "_");

                debugValue.expressionResult = ExecuteExpression((isPointer ? "" : "&") + propertyInfo[0].bstrFullName);
                if (Parse(debugValue.expressionResult, 16).GetValueOrDefault(0) == 0)
                {
                    throw new Exception("Incorrect argument!");
                }

                string typeName = null;
                if (visualizerId > 1000)
                {
                    debugProperty.GetCustomViewerCount(out uint viewersCount);
                    DEBUG_CUSTOM_VIEWER[] viewers = new DEBUG_CUSTOM_VIEWER[viewersCount];
                    debugProperty.GetCustomViewerList(0, viewersCount, viewers, out uint _);

                    for (uint i = 0; i != viewersCount; ++i)
                    {
                        if (System.Guid.Parse(viewers[i].bstrMetric) == typeof(IRuntimeDumperService).GUID &&
                            viewers[i].dwID == visualizerId)
                        {
                            debugValue.externalDumper = viewers[i].bstrMenuName;
                            typeName = viewers[i].bstrDescription;
                            break;
                        }
                    }
                    if (debugValue.externalDumper is null)
                    {
                        throw new Exception("External dumper is not found!");
                    }
                }
                else if (isReference)
                {
                    int length = propertyInfo[0].bstrType.Length;
                    typeName = propertyInfo[0].bstrType.Substring(0, length - 1) + " *";
                }
                else if (isPointer)
                {
                    typeName = propertyInfo[0].bstrType;
                }
                else
                {
                    typeName = propertyInfo[0].bstrType + " *";
                }
                debugValue.typeName = @"\""" + Regex.Replace(typeName, @"[\w.]+!", "") + @"\""";

                debugValues.Add(debugValue);
                int count = debugValues.Count;
                _ = System.Threading.Tasks.Task.Delay(1000).ContinueWith(t =>
                {
                    Dump(count);
                }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                dte.StatusBar.Text = "[Dumper] " + ex.Message;
                dte.StatusBar.Highlight(true);
                Utils.PrintMessage("Debug", "[Dumper] [ERROR] " + ex.Message, true);
                Utils.PrintMessage("Dumper", "[Dumper] [ERROR] " + ex.Message + "\n" + ex.StackTrace);
            }

            return(0);
        }
Exemplo n.º 4
0
        const uint elementSize = 4; // Size for int

        /// <summary>
        /// Plots the given vector contents in a modal window
        /// </summary>
        /// <param name="ownerHwnd">Parent window hwnd</param>
        /// <param name="visualizerId">The visualizer id to use</param>
        /// <param name="debugProperty">DebugProperty for a vector object</param>
        /// <returns>An HRESULT</returns>
        public int DisplayValue(uint ownerHwnd, uint visualizerId, IDebugProperty3 debugProperty)
        {
            int hr = VSConstants.S_OK;

            DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1];
            hr = debugProperty.GetPropertyInfo(
                enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ALL,
                10 /* Radix */,
                10000 /* Eval Timeout */,
                new IDebugReference2[] { },
                0,
                propertyInfo);

            Debug.Assert(hr == VSConstants.S_OK, "IDebugProperty3.GetPropertyInfo failed");

            // std::vector internally keeps pointers to the first and last elements of the dynamic array
            // First get the values of those members. We are going to use them later for reading vector elements.
            // An std::vector<int> variable has the following nodes in raw view:
            // myVector
            //      + std::_Vector_alloc<0,std::_Vec_base_types<int,std::allocator<int> > >
            //          + std::_Vector_val<std::_Simple_types<int> >
            //              + std::_Container_base12
            //              + _Myfirst
            //              + _Mylast
            //              + _Myend

            // This is the underlying base class of std::vector (std::_Vector_val<std::_Simple_types<int> > node above)
            DEBUG_PROPERTY_INFO vectorBaseClassNode = GetChildPropertyAt(0, GetChildPropertyAt(0, propertyInfo[0]));

            // myFirstInfo member points to the first element
            DEBUG_PROPERTY_INFO myFirstInfo = GetChildPropertyAt(1, vectorBaseClassNode);

            // myLastInfo member points to the last element
            DEBUG_PROPERTY_INFO myLastInfo = GetChildPropertyAt(2, vectorBaseClassNode);

            // Vector length can be calculated by the difference between myFirstInfo and myLastInfo pointers
            ulong startAddress = ulong.Parse(myFirstInfo.bstrValue.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
            ulong endAddress   = ulong.Parse(myLastInfo.bstrValue.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
            uint  vectorLength = (uint)(endAddress - startAddress) / elementSize;

            // Now that we have the address of the first element and the length of the vector,
            // we can read the vector elements from the debuggee memory.
            IDebugMemoryContext2 memoryContext;

            hr = myFirstInfo.pProperty.GetMemoryContext(out memoryContext);
            Debug.Assert(hr == VSConstants.S_OK, "IDebugProperty.GetMemoryContext failed");

            IDebugMemoryBytes2 memoryBytes;

            hr = myFirstInfo.pProperty.GetMemoryBytes(out memoryBytes);
            Debug.Assert(hr == VSConstants.S_OK, "IDebugProperty.GetMemoryBytes failed");

            // Allocate buffer on our side for copied vector elements
            byte[] vectorBytes = new byte[elementSize * vectorLength];
            uint   read        = 0;
            uint   unreadable  = 0;

            hr = memoryBytes.ReadAt(memoryContext, elementSize * vectorLength, vectorBytes, out read, ref unreadable);
            Debug.Assert(hr == VSConstants.S_OK, "IDebugMemoryBytes.ReadAt failed");

            // Create data series that will be needed by the plotter window and add vector elements to the series
            Series series = new Series();

            series.Name = propertyInfo[0].bstrName;

            for (int i = 0; i < vectorLength; i++)
            {
                series.Points.AddXY(i, BitConverter.ToUInt32(vectorBytes, (int)(i * elementSize)));
            }

            // Invoke plotter window to show vector contents
            PlotterWindow       plotterWindow = new PlotterWindow();
            WindowInteropHelper helper        = new WindowInteropHelper(plotterWindow);

            helper.Owner = (IntPtr)ownerHwnd;
            plotterWindow.ShowModal(series);

            return(hr);
        }
Exemplo n.º 5
0
        // Helper function to exercise the test target.
        int GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS fields, out DEBUG_PROPERTY_INFO propertyInfo)
        {
            var result = debugProperty.GetPropertyInfo(fields, out propertyInfo);

            return(result);
        }