Ejemplo n.º 1
0
        public static string HeapCellFileName(HeapCell aCell)
        {
            // Basic filename
            string basicName = aCell.Address.ToString("x8");

            return(basicName);
        }
Ejemplo n.º 2
0
 private void iContents_CellLinkDoubleClicked(HeapCell aCell)
 {
     if (iMainForm != null)
     {
         iMainForm.FocusedCell = aCell;
     }
 }
        public override void PopupShowAsyncImpl(HeapCellArrayWithStatistics aCells, HeapStatistics aStats, Point aLocalControlCoordinates, Point aScreenCoordinates, Size aOffsetBy, System.Windows.Forms.KeyEventHandler aKeyHandler)
        {
            PopupHide();
            //
            if (aCells.Count == 1)
            {
                HeapCell cell = aCells[0];
                //
                switch (cell.Type)
                {
                default:
                case HeapCell.TType.EAllocated:
                    if (cell.Symbol != null)
                    {
                        iActivePopup = new PopupCellAllocatedSymbols();
                    }
                    else
                    {
                        iActivePopup = new PopupCellAllocatedRaw();
                    }
                    break;

                case HeapCell.TType.EFree:
                    iActivePopup = new PopupCellFree();
                    break;
                }
            }
            else if (aCells.Count > 1)
            {
                iActivePopup = new PopupMultiCellSelection();
                iActivePopup.VisibilityDelay = 0;
            }
            //
            iActivePopup.PopupShowAsync(aScreenCoordinates, aCells, aStats, aOffsetBy, aKeyHandler);
        }
 public override void PrepareContent(HeapCellArrayWithStatistics aCells, HeapStatistics aStats)
 {
     try
     {
         HeapCell cell = aCells[0];
         System.Diagnostics.Debug.Assert(cell.Type == HeapCell.TType.EFree);
         //
         StringBuilder msg = new StringBuilder();
         //
         msg.AppendFormat("This free cell has a {0} byte header and a is occupying a total of {1} byte(s) of heap space.", cell.HeaderSize, cell.Length);
         msg.Append(System.Environment.NewLine + System.Environment.NewLine);
         //
         msg.AppendFormat("In total, this heap contains {0} bytes of free space.", aStats.StatsFree.TypeSize);
         msg.Append(System.Environment.NewLine + System.Environment.NewLine);
         //
         if (cell.Symbol != null)
         {
             // Free cells can contain symbols if we attempt to decode them...
             msg.AppendFormat("The free cell may have originally been of type \"{0}.\"", cell.SymbolString);
             msg.Append(System.Environment.NewLine + System.Environment.NewLine);
         }
         //
         iLbl_Description.Text = msg.ToString();
     }
     finally
     {
         base.PrepareContent(aCells, aStats);
     }
 }
        internal override void Track(HeapCell aCell)
        {
            if (aCell.Symbol != null && aCell.Symbol.IsDefault)
            {
                System.Diagnostics.Debug.WriteLine("Unknown cell: " + aCell.ToStringExtended() + ", size: " + aCell.Symbol.Size + ", " + aCell.Symbol.Object);
            }

            if (aCell.Type == HeapCell.TType.EAllocated && !aCell.IsUnknown)
            {
                System.Diagnostics.Debug.Assert(aCell.Symbol != null);

                base.HandleCell(aCell);

                uint         address = (uint)aCell.Symbol.Address;
                TrackingInfo entry   = iList[address];

                // If we found an entry, then associate this cell with it.
                // Otherwise, we'll need to make a new entry...
                if (entry == null)
                {
                    entry = new TrackingInfo(aCell.Symbol);
                    entry.PayloadLength = aCell.PayloadLength;

                    iList.Add(address, entry);
                }
                entry.Associate(aCell);
            }
        }
        private string CreateCellContentsQuickView(HeapCell aCell)
        {
            const int KDWordsPerLine = 4;

            StringBuilder ret = new StringBuilder();

            //
            ret.Append("<table>");

            int rawItemsCount = Math.Min(KDWordsPerLine * 2, aCell.RawItems.Count);

            for (int i = 0; i < rawItemsCount; i += KDWordsPerLine)
            {
                ret.Append("<tr>");

                // Work out how many items on this line
                int     runIndex;
                int     runExtent = i + KDWordsPerLine;
                RawItem rawItem   = null;

                // First set of columns - original data
                for (runIndex = i; runIndex < runExtent; runIndex++)
                {
                    // Get the item
                    if (runIndex < rawItemsCount)
                    {
                        rawItem = aCell[runIndex];
                        ret.Append("<td align=center>" + rawItem.OriginalData.ToString("x8") + "</td>");
                    }
                    else
                    {
                        ret.Append("<td></td>");
                        rawItem = null;
                    }
                }

                ret.Append("<td>&nbsp;</td>");

                // Second set of columns - characterised data
                for (runIndex = i; runIndex < runExtent; runIndex++)
                {
                    // Get the item
                    if (runIndex < rawItemsCount)
                    {
                        rawItem = aCell[runIndex];
                        ret.Append("<td align=center>" + HTMLEntityUtility.Entitize(rawItem.OriginalCharacterisedData) + "</td>");
                    }
                    else
                    {
                        ret.Append("<td></td>");
                        rawItem = null;
                    }
                }

                ret.Append("</tr>");
            }
            ret.Append("</table>");
            //
            return(ret.ToString());
        }
Ejemplo n.º 7
0
        private void DoWriteHeapToFile(StreamWriter aWriter)
        {
            aWriter.WriteLine("Cell\t\tCounter\t\tLength\t\tSymbol");
            aWriter.WriteLine("");
            //
            HeapCellArray heapItems = iReconstructor.Data;

            for (int r = 0; r < heapItems.Count; r++)
            {
                HeapCell entry = (HeapCell)heapItems[r];
                //
                if (iShowOnlySymbolicMatches == false || (iShowOnlySymbolicMatches == true && entry.Symbol != null))
                {
                    StringBuilder line = new StringBuilder();
                    //
                    line.Append(entry.Address.ToString("x8"));
                    line.Append("\t");
                    line.Append(entry.AllocationNumber.ToString("d8"));
                    line.Append("\t");
                    line.Append(entry.Length.ToString("x8"));
                    line.Append("\t");
                    if (entry.Symbol != null)
                    {
                        line.Append(entry.Symbol.Name);
                    }
                    //
                    aWriter.WriteLine(line.ToString());
                }
            }
        }
        private const int KMinimumUtilisationPercentage = 10; // Percent
        #endregion

        #region Internal methods
        private static int AsPercentage(HeapCell aCell, int aLength)
        {
            uint  totalLength = aCell.PayloadLength;
            float ret         = ((float)aLength / (float)totalLength) * 100.0f;

            return((int)ret);
        }
        private static TreeNode CreateChildNode(HeapCell aParent, HeapCell aCell, RelationshipInfo aRelationshipDescriptor /* optional */)
        {
            StringBuilder caption = new StringBuilder();

            caption.Append("[" + aCell.Address.ToString("x8") + "] ");
            if (aRelationshipDescriptor != null)
            {
                caption.Append("[" + aRelationshipDescriptor.LinkAddressOffsetWithinFromCell.ToString("d4") + "] ");
            }
            caption.Append("[" + aCell.PayloadLength.ToString("d6") + "] ");
            //
            System.Drawing.Color foreColour = Color.Black;
            if (aCell.Symbol != null)
            {
                caption.Append(aCell.Symbol.NameWithoutVTablePrefix);
                foreColour = Color.Blue;
            }
            else
            {
                caption.Append("No symbol");
                foreColour = Color.LightGray;
            }
            //
            TreeNode node = new TreeNode(caption.ToString());

            node.ForeColor = foreColour;
            return(node);
        }
        private void UpdateSizingTextBoxByType(TSizingType aType)
        {
            string size = string.Empty;
            //
            TreeNode node = iTreeView.SelectedNode;

            if (node != null && node.Tag != null && node.Tag is HeapCell)
            {
                HeapCell selectedCell = (HeapCell)node.Tag;
                //
                switch (aType)
                {
                case TSizingType.ESizingTypePayloadSize:
                    size = selectedCell.PayloadLength.ToString("d12");
                    break;

                case TSizingType.ESizingTypePayloadSizeIncludingChildren:
                    size = selectedCell.PayloadLengthIncludingLinkedCells.ToString("d12");
                    break;

                case TSizingType.ESizingTypePayloadSizeJustChildren:
                    size = (selectedCell.PayloadLengthIncludingLinkedCells - selectedCell.PayloadLength).ToString("d12");
                    break;

                case TSizingType.ESizingTypePayloadSizeRecursive:
                    size = selectedCell.CombinedLinkedCellPayloadLengths.ToString("d12");
                    break;

                default:
                    break;
                }
            }
            //
            iTextBox_CombinedSize.Text = size;
        }
        public override void PrepareContent(HeapCellArrayWithStatistics aCells, HeapStatistics aStats)
        {
            try
            {
                HeapCell cell = aCells[0];
                System.Diagnostics.Debug.Assert(cell.Type == HeapCell.TType.EAllocated);
                System.Diagnostics.Debug.Assert(cell.Symbol != null);
                RelationshipManager relMgr = cell.RelationshipManager;
                //
                TrackingInfo info      = aStats.StatsAllocated.TrackerSymbols[cell.Symbol];
                int          instCount = info.AssociatedCellCount;
                //
                Title = instCount + " Instance(s)";
                //
                StringBuilder msg = new StringBuilder();
                //
                msg.AppendFormat("This allocated cell is an instance of {0} from {1}", cell.Symbol.NameWithoutVTablePrefix, cell.Symbol.ObjectWithoutSection);
                msg.Append(System.Environment.NewLine + System.Environment.NewLine);

                msg.AppendFormat("There {0} {1} instance{2} of this symbol, with each instance using {3} bytes of memory (plus cell header overhead).", (instCount == 0 || instCount > 1) ? "are" : "is", info.AssociatedCellCount, (instCount == 0 || instCount > 1) ? "s" : string.Empty, cell.PayloadLength);
                msg.Append(System.Environment.NewLine + System.Environment.NewLine);
                //
                msg.AppendFormat("In total, cells of this type use {0} bytes of heap memory", info.AssociatedMemory);
                msg.Append(System.Environment.NewLine + System.Environment.NewLine);
                //
                msg.AppendFormat("This cell references {0} other cell(s), and is referenced by {1} cell(s)", relMgr.EmbeddedReferencesTo.Count, relMgr.ReferencedBy.Count);
                msg.Append(System.Environment.NewLine + System.Environment.NewLine);
                //
                iLbl_Description.Text = msg.ToString();
            }
            finally
            {
                base.PrepareContent(aCells, aStats);
            }
        }
Ejemplo n.º 12
0
    /// <summary>
    /// adds heapcell to the heap using the given sort-value
    /// </summary>
    /// <param name="cell">heapcell to be used</param>
    private void add(HeapCell <T> cell)
    {
        size++;

        if ((size * 2 + 1) >= _length)
        {
            grow(size);
        }

        _data[size] = cell;

        int i = size;

        //do any needed swapping
        while (i != 1)
        {
            //compare cells
            if (_data[i].value <= _data[i / 2].value)
            {
                //if i is less than i/2, swap
                HeapCell <T> temp = _data[i / 2];
                _data[i / 2] = _data[i];
                _data[i]     = temp;
                i            = i / 2;
            }
            else            //otherwise break
            {
                break;
            }
        }
    }
        private void DoFinaliseCell(object aCell)
        {
            HeapCell cell = (HeapCell)aCell;

            // Do symbolic lookups
            Debug("  {0x" + iState.CurrentAddress.ToString("x8") + "} - vTable:      " + cell.PossibleVTableAddress.ToString("x8"));
            cell.Symbol = FindMatchingSymbolVTable(cell.PossibleVTableAddress, cell.Length);

            // If the MemSpy data includes stack-based function addresses stored instead
            // of nesting level, then we can also try to find a matching symbol.
            if (SourceData.MetaData.Heap.IsDebugAllocatorWithStoredStackAddresses)
            {
                cell.Symbol2 = FindMatchingSymbolAny(cell.NestingLevel);
                cell.Symbol3 = FindMatchingSymbolAny(cell.AllocationNumber);
            }

            // Cell is now finished.
            cell.ConstructionComplete(iStatistics);

            // Update stats - do this after finalising the cell
            // as the act of finalisation may result in the
            // cell being tagged as a descriptor. This must be done
            // prior to the stats update, or else we won't treat
            // any cell as a descriptor!
            lock ( iStatistics )
            {
                iStatistics.HandleCell(cell);
            }
        }
        protected override void OnRowComplete(HeapCell aCell, int aRow, int aNextFreeColumn)
        {
            if (iReconstructor.SourceData.MetaData.Heap.IsDebugAllocatorWithStoredStackAddresses)
            {
                if (aCell.IsUnknown && aCell.Type == HeapCell.TType.EAllocated)
                {
                    object[ , ] items = new object[1, 2];

                    if (aCell.Symbol2 != null)
                    {
                        items[0, 0] = aCell.Symbol2.Name;
                    }
                    else
                    {
                        items[0, 0] = string.Empty;
                    }

                    if (aCell.Symbol3 != null)
                    {
                        items[0, 1] = aCell.Symbol3.Name;
                    }
                    else
                    {
                        items[0, 1] = string.Empty;
                    }

                    Range range = Utils.GetRangeByColumnAndRow(aRow, 5, aRow, 6, Worksheet);
                    range.Value2 = items;
                }
            }
        }
Ejemplo n.º 15
0
        public void PopupShowAsync(Point aLocation, HeapCell aCell, RawItem aItem, HeapStatistics aStats, Size aOffset, System.Windows.Forms.KeyEventHandler aKeyHandler)
        {
            //System.Diagnostics.Debug.WriteLine( "PopupBase - Timer Started" );
            iKeyHandler = aKeyHandler;

            HeapCellArrayWithStatistics array = new HeapCellArrayWithStatistics();

            array.Add(aCell);
            PrepareContent(array, aStats, aItem);
            //
            iHoverPos = aLocation;
            //
            iShowPos = aLocation;
            iShowPos.Offset(aOffset.Width, aOffset.Height);

            // If we are using an async timer delay then we must start the timer and
            // when it expires, the popup will become visible. Otherwise, we show
            // the popup immediately.
            if (VisibilityDelay > 0)
            {
                iTimer.Stop();
                iTimer.Enabled = true;
                iTimer.Start();
            }
            else
            {
                PopupShow();
            }
        }
Ejemplo n.º 16
0
        private Color ColourForHeapCell(HeapCell aCell)
        {
            Color ret = KBaselineColourDescriptor;

            //
            if (!aCell.IsDescriptor)
            {
                float rF = KRampBaselineColourStart.R;
                float gF = KRampBaselineColourStart.G;
                float bF = KRampBaselineColourStart.B;
                //
                float count = aCell.RelationshipManager.EmbeddedReferencesTo.Count + 1.0f;
                float val   = (float)Math.Log(count);
                val /= iDomain;
                //
                rF += ((KRampBaselineColourEnd.R - KRampBaselineColourStart.R) * val);
                gF += ((KRampBaselineColourEnd.G - KRampBaselineColourStart.G) * val);
                bF += ((KRampBaselineColourEnd.B - KRampBaselineColourStart.B) * val);
                //
                int r = Math.Min(Math.Max(0, (int)rF), 255);
                int g = Math.Min(Math.Max(0, (int)gF), 255);
                int b = Math.Min(Math.Max(0, (int)bF), 255);
                //
                return(System.Drawing.Color.FromArgb(r, g, b));
            }
            //
            return(ret);
        }
        public static DescriptorInfo DescriptorInfo(HeapCell aCell, HeapStatistics aStats)
        {
            DescriptorInfo ret = null;

            //
            if (iAlgorithms.Count == 0)
            {
                PrepareAlgorithms(aStats);
            }
            //
            foreach (DescriptorAlgorithmBase alg in iAlgorithms)
            {
                bool isDes = alg.IsDescriptor(aCell, out ret);
                if (isDes && ret != null)
                {
                    // We won't allow any algorithm to "recognise" the heap cell as a descriptor
                    // unless it can say that the length is > 0.
                    int length = ret.Length;
                    if (length > 0)
                    {
                        break;
                    }
                    else
                    {
                        ret = null;
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 18
0
 public void HeapCellRenderingComplete(Graphics aGraphics, HeapCell aCell, HeapCellMetaData aMetaData)
 {
     SelectionBorder.HeapCellRenderingComplete(aGraphics, aCell, aMetaData);
     Header.HeapCellRenderingComplete(aGraphics, aCell, aMetaData);
     Content.HeapCellRenderingComplete(aGraphics, aCell, aMetaData);
     ContentBorder.HeapCellRenderingComplete(aGraphics, aCell, aMetaData);
 }
Ejemplo n.º 19
0
 public override void PrepareContent(HeapCellArrayWithStatistics aCells, HeapStatistics aStats, RawItem aRawItem)
 {
     try
     {
         System.Diagnostics.Debug.Assert(aCells.Count == 1);
         System.Diagnostics.Debug.Assert(aRawItem.Tag != null && aRawItem.Tag is RelationshipInfo);
         HeapCell            cell    = aCells[0];
         RelationshipManager relMgr  = cell.RelationshipManager;
         RelationshipInfo    relInfo = (RelationshipInfo)aRawItem.Tag;
         //
         StringBuilder msg = new StringBuilder();
         //
         msg.AppendFormat("This is an embedded reference to the cell at address 0x{0}", relInfo.ToCell.Address.ToString("x8"));
         if (relInfo.ToCell.Symbol != null)
         {
             msg.AppendFormat(", which is an instance of a {0} object.", relInfo.ToCell.SymbolString);
         }
         msg.Append(System.Environment.NewLine + System.Environment.NewLine);
         //
         msg.AppendFormat("In total, this cell references {0} other cell(s), and is referenced by {1} cell(s)", relMgr.EmbeddedReferencesTo.Count, relMgr.ReferencedBy.Count);
         msg.Append(System.Environment.NewLine + System.Environment.NewLine);
         //
         iLbl_Description.Text = msg.ToString();
     }
     finally
     {
         base.PrepareContent(aCells, aStats, aRawItem);
     }
 }
        private void Navigator_NavNewColumn(HeapCell aCell, HeapCellMetaData aMetaData, uint aAddress, Point aPixelPos, Point aBoxPos, Size aDimensions, Size aBoxSize, Size aPadding)
        {
            // Draw content
            iFactory.Renderers.Content.PaintContent(iGraphics, aMetaData, aCell, aAddress, aPixelPos, aBoxSize, aPadding);

            // Draw cell border
            iFactory.Renderers.ContentBorder.PaintContentBorder(iGraphics, aMetaData, aCell, aAddress, aPixelPos, aBoxSize, aPadding);

            // If we are handling a click & drag operation, then check whether the cell
            // needs a border.
            if (iMouseSelectionCell != null)
            {
                // Get the cell index within the cell array
                int index           = CellIndex(aCell);
                int mouseBoundLower = (int)iMouseSelectionCellBoundaryLower.Tag;
                int mouseBoundUpper = (int)iMouseSelectionCellBoundaryUpper.Tag;

                if (index >= mouseBoundLower && index <= mouseBoundUpper)
                {
                    iFactory.Renderers.SelectionBorder.PaintSelectionBorder(iGraphics, aMetaData, aCell, aAddress, aPixelPos, aBoxSize, aPadding, THeapSelectionBorderType.ESelectionMouse);
                }
            }
            else if (iFocusedCellKeyboard == aCell)
            {
                // Draw border around currently mouse over'd cell
                iFactory.Renderers.SelectionBorder.PaintSelectionBorder(iGraphics, aMetaData, aCell, aAddress, aPixelPos, aBoxSize, aPadding, THeapSelectionBorderType.ESelectionKeyboard);
            }
            else if (iFocusedCellMouse == aCell)
            {
                // Draw border around currently mouse over'd cell
                iFactory.Renderers.SelectionBorder.PaintSelectionBorder(iGraphics, aMetaData, aCell, aAddress, aPixelPos, aBoxSize, aPadding, THeapSelectionBorderType.ESelectionMouse);
            }
        }
 internal virtual void HandleCell(HeapCell aCell)
 {
     ++iTypeCount;
     //
     iTypeSizeHeader  += aCell.HeaderSize;
     iTypeSizePayload += aCell.PayloadLength;
     //
     iDistribution.Register(aCell.Length);
     //
     if (iCellLargest == null || aCell.Length > iCellLargest.Length)
     {
         iCellLargest = aCell;
     }
     if (iCellSmallest == null || aCell.Length < iCellSmallest.Length)
     {
         iCellSmallest = aCell;
     }
     //
     if (iCellAllocationNumberLargest == null || aCell.AllocationNumber > iCellAllocationNumberLargest.AllocationNumber)
     {
         iCellAllocationNumberLargest = aCell;
     }
     if (iCellAllocationNumberSmallest == null || aCell.AllocationNumber > iCellAllocationNumberSmallest.AllocationNumber)
     {
         iCellAllocationNumberSmallest = aCell;
     }
 }
        public HeapCell CellByBoxCoordinates(Point aBoxCoordinates)
        {
            uint     address = AddressByBoxCoordinates(aBoxCoordinates);
            HeapCell ret     = Cells.CellByAddress(address);

            return(ret);
        }
        public int CellIndex(HeapCell aCell)
        {
            int index = -1;

            Cells.CellByExactAddress(aCell.Address, out index);
            return(index);
        }
Ejemplo n.º 24
0
 private void iRenderer_CellDoubleClicked(HeapCell aCell)
 {
     if (CellDoubleClicked != null)
     {
         CellDoubleClicked(aCell);
     }
 }
Ejemplo n.º 25
0
        public static Color ColourByCellType(HeapCell aCell, out bool aIsUnknown)
        {
            aIsUnknown = false;
            Color ret = Color.WhiteSmoke;

            //
            switch (aCell.Type)
            {
            case HeapCell.TType.EAllocated:
            {
                if (aCell.IsDescriptor)
                {
                    ret = CellAllocatedDescriptor;
                }
                else if (aCell.Symbol != null)
                {
                    ret = CellAllocatedWithSymbol;
                }
                else
                {
                    aIsUnknown = true;
                    ret        = CellAllocatedUnknown;
                }
                break;
            }

            case HeapCell.TType.EFree:
                ret = CellFree;
                break;
            }
            //
            return(ret);
        }
        public void HeapCellRenderingComplete(Graphics aGraphics, HeapCell aCell, HeapCellMetaData aMetaData)
        {
            Color fillColour = RampedColourByIntensityRange(KBiggestCellColour, aCell.Length, iCellLengthSmallest, iCellLengthLongest);
            //
            string text = aCell.SymbolStringWithoutDescriptorPrefix;

            PaintBoxedTextWithLuminanceHandling(text, aGraphics, fillColour);
        }
Ejemplo n.º 27
0
 private void iRenderer_CellRightClicked(HeapCell aCell, RawItem aRawItem, Point aViewerPos)
 {
     if (CellRightClicked != null)
     {
         Point screenPos = iRenderer.PointToScreen(aViewerPos);
         CellRightClicked(aCell, aRawItem, screenPos);
     }
 }
Ejemplo n.º 28
0
        public void HeapCellRenderingComplete(Graphics aGraphics, HeapCell aCell, HeapCellMetaData aMetaData)
        {
            Color fillColour = ColourForHeapCell(aCell);
            //
            string text = aCell.SymbolStringWithoutDescriptorPrefix;

            PaintBoxedTextWithLuminanceHandling(text, aGraphics, fillColour);
        }
Ejemplo n.º 29
0
 public override HeapCell this[int aIndex]
 {
     get
     {
         HeapCell ret = iItems[aIndex];
         return(ret);
     }
 }
Ejemplo n.º 30
0
        public static string HeapCellFileNameAndPath(HeapCell aCell, string aBasePath, string aStandardSubDir)
        {
            string basicName        = HeapCellFileName(aCell);
            string combinedSubDir   = HeapCellDirectory(aCell, aStandardSubDir, System.IO.Path.DirectorySeparatorChar);
            string heapDataFileName = HeapToHTMLConverter.PageFileNameEnsuringPathExists(basicName, aBasePath, combinedSubDir);

            return(heapDataFileName);
        }