예제 #1
0
 protected void ParseCommonAlloc(MemOpAllocation aOperation, ref string aLine, MemAnalysisParserPrefixesBase aPrefixes)
 {
     if (aLine.IndexOf(aPrefixes.AllocSize) >= 0)
     {
         PrefixParser.SkipPrefix(aPrefixes.AllocSize, ref aLine);
         aOperation.AllocationSize = PrefixParser.ReadUint(ref aLine);
     }
 }
예제 #2
0
        public MemObjStatisticalCollection CollectionBySymbol(MemOpBase aItem)
        {
            System.Diagnostics.Debug.Assert(aItem.IsAllocationType || aItem.IsReallocationType);
            //
            MemOpAllocation             allocObject = (MemOpAllocation)aItem;
            MemObjStatisticalCollection ret         = CollectionBySymbol(allocObject.LinkRegisterSymbol, allocObject.LinkRegisterAddress);

            //
            return(ret);
        }
        private void UpdateMemoryAnalysisGridForSelectedSymbol()
        {
            lock (this)
            {
                iStopPopulatingGrid = false;
            }
            //
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                //
                if (iListView.SelectedIndices.Count > 0)
                {
                    MemObjStatisticalData data = iParser.Data;
                    int selectedIndex          = iListView.SelectedIndices[0];

                    ListViewItem selectedItem = iListView.SelectedItems[0];
                    if (selectedItem.Tag != null)
                    {
                        MemObjStatisticalCollection collection = (MemObjStatisticalCollection)selectedItem.Tag;
                        MemOpBase baseObject = collection[0];
                        System.Diagnostics.Debug.Assert(baseObject is MemOpAllocation);
                        MemOpAllocation memObj = (MemOpAllocation)baseObject;
                        //
                        string symbolText = "Unknown";
                        if (memObj.LinkRegisterSymbol != null && memObj.LinkRegisterSymbol.Symbol != null)
                        {
                            symbolText = memObj.LinkRegisterSymbol.Symbol.ToString();
                        }
                        iMemAnalysisDetailedInfoForSymbolGroupBox.Text = @"Detailed Analysis for Symbol '" + symbolText + @"'";
                        //
                        PopulateTableRows(collection);
                    }
                }
            }
            catch (Exception)
            {
                iGridIsDirty = false;
            }
            finally
            {
                Cursor.Current      = Cursors.Default;
                iStopPopulatingGrid = false;
                //iListView.Enabled = false;
                //iListView.Select();
            }

            lock (this)
            {
                iGridIsDirty = false;
            }
        }
예제 #4
0
        public override MemOpBase Parse(ref string aLine, MemAnalysisParserPrefixesBase aPrefixes)
        {
            MemOpAllocation ret = new MemOpAllocation();

            // Parse fields
            base.ParseCommonKernel(ret, ref aLine, aPrefixes);
            ParseCommonAlloc(ret, ref aLine, aPrefixes);

            // Set type
            ret.Function = this;

            return(ret);
        }
예제 #5
0
        public MemObjStatisticalCollection CollectionBySymbol(SymbolLib.Generics.GenericSymbol aSymbol, uint aAddress)
        {
            // We also need a symbol...
            MemObjStatisticalCollection ret = null;

            //
            if (aSymbol != null)
            {
                int count = iCollections.Count;
                for (int i = 0; i < count; i++)
                {
                    MemObjStatisticalCollection collection = (MemObjStatisticalCollection)iCollections[i];
                    if (collection != iNullSymbolCollection)
                    {
                        System.Diagnostics.Debug.Assert(collection.Count > 0);
                        MemOpAllocation compareToObject = (MemOpAllocation)collection[0];

                        // Comparing the link register address is a very specific match - therefore we
                        // prefer the slightly slower comparison against the symbol name. This prevents
                        // multiple entries in the list that come from the same symbol (but different
                        // instruction address).. i.e. the allocation occurs within the same function,
                        // but a slightly different location.
                        if (compareToObject.LinkRegisterSymbol != null)
                        {
                            if (compareToObject.LinkRegisterSymbol.Symbol == aSymbol.Symbol)
                            {
                                ret = collection;
                                break;
                            }
                        }
                        else if (compareToObject.LinkRegisterAddress == aAddress)
                        {
                            // Symbols match, add it to this container
                            ret = collection;
                            break;
                        }
                    }
                }
            }
            else
            {
                // Must be from the null symbol collection then.
                ret = iNullSymbolCollection;
            }
            //
            return(ret);
        }
예제 #6
0
 protected override void HandleOpAllocation(MemOpAllocation aObject)
 {
     iData.Add(aObject, Options.DiscardMatchingAllocsAndFrees);
 }
예제 #7
0
 protected abstract void HandleOpAllocation(MemOpAllocation aObject);
예제 #8
0
        public void Add(MemOpBase aItem, bool aDiscardAllocAndFreedMatchingCells)
        {
            /*
             * if ( aItem.CellAddress == 0xc8036684 )
             * {
             *  int x = 0;
             *  x++;
             *  MemOpAllocation ob = (MemOpAllocation) aItem;
             *  if	( ob.LinkRegisterAddress == 0x80874729 )
             *  {
             *      int x = 0;
             *      x++;
             *  }
             * }
             */


            int allItemCount = iAllItems.Count;

            // Check for chained operations - we just treat it as a high level op in that case.
            if (aItem.Function.ChainedFunction != null && allItemCount > 0)
            {
                MemOpBase lastOp = PriorOperationByAllocationNumber(aItem.AllocationNumber);
                if (lastOp != null &&
                    lastOp.AllocationNumber == aItem.AllocationNumber &&
                    lastOp.CellAddress == aItem.CellAddress &&
                    lastOp.Class == aItem.Class &&
                    lastOp.Function.ToString() == aItem.Function.ChainedFunction.ToString())
                {
                    // The current operation, replaces the prior one.
                    RemoveFromCollection(lastOp);
                    RemovePriorOperation(lastOp);
                    allItemCount = iAllItems.Count;

                    // Also, we must reset any linkage that the prior operation may have
                    // created when it was added.
                    if (lastOp.Link != null)
                    {
                        lastOp.Link.Link = null;
                    }
                }
            }

            // If the item is a de-allocation, hunt backwards through the allocation
            // list until we find the allocating cell. Then setup their two-way relationship
            bool saveItem = true;

            if (aItem.IsDeallocationType)
            {
                MemOpBase lastOp = PriorOperationByAllocationNumber(aItem.AllocationNumber);
                if (aItem.Function.ChainedFunction != null && lastOp != null && lastOp.Class == TClass.EDeallocation)
                {
                    if (lastOp.CellAddress == aItem.CellAddress &&
                        lastOp.Function.ToString() == aItem.Function.ChainedFunction.ToString())
                    {
                        if (aDiscardAllocAndFreedMatchingCells)
                        {
                            // This is a chained delete operation, e.g:
                            //
                            // [KMEM] OKF     - C: 0xc802776c, HS:    80064, HCS:    85896, LR: 0x800c98c4, AS:      316, AN:      314, VT: 0x800d09c8
                            // [KMEM] OD      - C: 0xc802776c, HS:    80064, HCS:    85896, LR: 0x800a2ea8, AS:      316, AN:      314, VT: 0x800d09c8
                            // [KMEM] ODBD    - C: 0xc802776c, HS:    80064, HCS:    85896, LR: 0x800adec8, AS:      316, AN:      314, VT: 0x800d0000
                            //
                            // and we're handling OD or ODBD after already having processed OKF. In that case, we've already thrown away the original
                            // alloc, and there's nothing left for us to do here.
                            saveItem = false;
                        }
                        else
                        {
                            // We need to replace the OKF/OD operation with the OD/ODBD respectively. In order
                            // for the loop below to process the item, we must re-nullify the link
                            MemOpBase originalAllocationOp = lastOp.Link;
                            originalAllocationOp.Link = null;
                        }
                    }
                }

                // If the item is a deallocation, but we can't find any matching alloc
                // then just ignore the deallocation entirely.
                //
                // We'll assume that its an isolated dealloc, but if we find a matching
                // alloc we'll toggle this back again to preseve the item.
                saveItem = false;
                //
                for (int i = allItemCount - 1; i >= 0; i--)
                {
                    MemOpBase item = iAllItems[i];
                    //
                    if (item.Link == null && item.CellAddress == aItem.CellAddress && item.IsAllocationType != aItem.IsAllocationType)
                    {
                        // The item should be the allocation that this de-alloc is associated
                        // with..
                        if (aDiscardAllocAndFreedMatchingCells)
                        {
                            // Can ignore both the allocation and deallocation.
                            RemoveFromCollection(item);
                            iAllItems.RemoveAt(i);

                            // Don't save the delete - we are ignoring matching alloc & frees
                            break;
                        }
                        else
                        {
                            item.Link  = aItem;
                            aItem.Link = item;
                            saveItem   = true;
                            break;
                        }
                    }
                }
            }

            // Add the item to our master list...
            if (saveItem)
            {
                // Locate the corresponding collection and also add the item there too
                MemOpAllocation searchObject = null;
                if (aItem.IsAllocationType)
                {
                    searchObject = (MemOpAllocation)aItem;
                }
                else
                {
                    // Try to base the search object on the link item (if we have one..)
                    if (aItem.Link != null)
                    {
                        searchObject = (MemOpAllocation)aItem.Link;
                    }
                }

                if (searchObject != null)
                {
                    if (searchObject.LinkRegisterSymbol != null)
                    {
                        MemObjStatisticalCollection collection = CollectionBySymbol(searchObject);
                        if (collection == null)
                        {
                            // Make a new collection
                            collection = new MemObjStatisticalCollection();
                            iCollections.Add(collection);
                        }
                        collection.Add(aItem);
                    }
                    else
                    {
                        // Use the null symbol collection
                        iNullSymbolCollection.Add(aItem);
                    }
                }

                AddNewPriorOperation(aItem);
            }
        }
예제 #9
0
        private void PrepareGridForSelectedListItem()
        {
            if (!(iPreparingGrid || iListView.SelectedItems.Count == 0 || iListView.SelectedItems[0].Tag == null))
            {
                iPreparingGrid    = true;
                iListView.Enabled = false;
                Cursor.Current    = Cursors.WaitCursor;
                //
                ListViewItem             listItem   = iListView.SelectedItems[0];
                MemObjRegionalCollection collection = (MemObjRegionalCollection)listItem.Tag;
                //
                try
                {
                    // First update the text labels to show the marker values
                    iMarkerStartText.Text = collection.RegionStart.RegionText;
                    iMarkerEndText.Text   = collection.RegionEnd.RegionText;

                    // Clear existing content
                    iTable.TableModel.Rows.Clear();

                    // Make new content
                    int count = collection.Count;
                    for (int i = 0; i < count; i++)
                    {
                        // The entry we are rendering
                        MemOpBase baseObject = collection[i];

                        // Only initialised if we are dealing with an allocation (or realloc) type cell.
                        MemOpAllocation memObj = null;

                        // The color format for the entire row.
                        System.Drawing.Color rowColor = Color.Black;

                        // The row we are creating
                        XPTable.Models.Row row = new XPTable.Models.Row();

                        // Common items
                        // ============
                        row.Cells.Add(new XPTable.Models.Cell(baseObject.OperationIndex.ToString("d6")));
                        row.Cells.Add(new XPTable.Models.Cell(baseObject.LineNumber.ToString("d6")));
                        row.Cells.Add(new XPTable.Models.Cell(baseObject.CellAddress.ToString("x8")));
                        row.Cells.Add(new XPTable.Models.Cell(" " + baseObject.FunctionName));

                        // Row Color & Object Association
                        // ==============================
                        if (baseObject is MemOpAllocation)
                        {
                            // Allocation
                            memObj   = (MemOpAllocation)baseObject;
                            rowColor = Color.Red;
                        }
                        else if (baseObject is MemOpFree)
                        {
                            // Deallocation
                            if (baseObject.Link != null)
                            {
                                memObj = (MemOpAllocation)baseObject.Link;
                            }
                            else
                            {
                                memObj = null;
                            }
                            rowColor = Color.Green;
                        }
                        else if (baseObject is MemOpReallocation)
                        {
                            // Reallocation
                            if (baseObject.Link != null)
                            {
                                memObj = (MemOpAllocation)baseObject.Link;
                            }
                            else
                            {
                                memObj = null;
                            }
                            rowColor = Color.Blue;
                        }

                        // Allocation size
                        // ===============
                        string allocationSize = "???";
                        if (memObj != null)
                        {
                            allocationSize = memObj.AllocationSize.ToString();
                        }
                        row.Cells.Add(new XPTable.Models.Cell(allocationSize + "  "));

                        // Heap size
                        // =========
                        row.Cells.Add(new XPTable.Models.Cell(baseObject.HeapSize.ToString() + "  "));

                        // Associated object
                        // =================
                        MemOpAllocation symbolObject = memObj;
                        if (memObj != null && baseObject.Link != null)
                        {
                            // If we have an associated link item, we can connect the two items together
                            string associatedText = string.Empty;
                            if (baseObject.IsAllocationType)
                            {
                                associatedText = "Free'd by op #:  " + baseObject.Link.OperationIndex.ToString("d5");
                            }
                            else if (baseObject.IsReallocationType)
                            {
                                associatedText = "First alloc'd by op #: " + baseObject.Link.OperationIndex.ToString("d5");
                                symbolObject   = (baseObject.Link as MemOpAllocation);
                            }
                            else
                            {
                                associatedText = "Alloc'd by op #: " + baseObject.Link.OperationIndex.ToString("d5");
                            }

                            // We store the object with the cell so that we can handle hyperlinks between
                            // associated objects.
                            XPTable.Models.Cell associatedCell = new XPTable.Models.Cell(associatedText);
                            associatedCell.Tag = baseObject;

                            // Make it look like a hyperlink
                            associatedCell.Font = new Font(iTable.Font.FontFamily.Name, iTable.Font.SizeInPoints, System.Drawing.FontStyle.Underline);

                            // Add the cell to the row
                            row.Cells.Add(associatedCell);
                        }
                        else
                        {
                            if (baseObject.IsAllocationType)
                            {
                                if (memObj != null)
                                {
                                    symbolObject = memObj;
                                }

                                rowColor = Color.Red;
                                row.Font = new System.Drawing.Font(iTable.Font.FontFamily.Name, iTable.Font.SizeInPoints, System.Drawing.FontStyle.Bold);
                                row.Cells.Add(new XPTable.Models.Cell("Object never free'd!"));
                            }
                            else
                            {
                                row.Cells.Add(new XPTable.Models.Cell("???!"));
                            }
                        }

                        // Symbol
                        // ======
                        string symbol = string.Empty;
                        if (symbolObject != null && symbolObject.LinkRegisterSymbol != null)
                        {
                            symbol = memObj.LinkRegisterSymbol.Symbol.ToString();
                        }
                        row.Cells.Add(new XPTable.Models.Cell(symbol));

                        // Set row color
                        // =============
                        row.ForeColor = rowColor;

                        // Add row
                        // =======
                        iTable.TableModel.Rows.Add(row);
                    }

                    // If no items, then dim table
                    iTable.Enabled = (count > 0);
                }
                finally
                {
                    Cursor.Current    = Cursors.Default;
                    iPreparingGrid    = false;
                    iListView.Enabled = true;
                    iListView.Select();
                }
            }
        }
        private void PopulateTableRows(MemObjStatisticalCollection aCollection)
        {
            // Clear existing content
            iGrid.BeginUpdate();
            iGrid.TableModel.Rows.Clear();
            iGrid.Tag = aCollection;

            // Make new content
            int count = aCollection.Count;

            for (int i = 0; i < count; i++)
            {
                // The entry we are rendering
                MemOpBase baseObject = aCollection[i];

                // Only initialised if we are dealing with an allocation (or realloc) type cell.
                MemOpAllocation memObj = null;

                // The color format for the entire row.
                System.Drawing.Color rowColor = Color.Black;

                // The row we are creating
                XPTable.Models.Row row = new XPTable.Models.Row();

                // Set tag for the row
                row.Tag = baseObject;

                // Common items
                // ============
                XPTable.Models.Cell opIndexCell = new XPTable.Models.Cell(baseObject.OperationIndex.ToString("d6"));
                row.Cells.Add(opIndexCell);
                XPTable.Models.Cell lineNumberCell = new XPTable.Models.Cell(baseObject.LineNumber.ToString("d6"));
                row.Cells.Add(lineNumberCell);
                XPTable.Models.Cell cellAddressCell = new XPTable.Models.Cell(baseObject.CellAddress.ToString("x8"));
                row.Cells.Add(cellAddressCell);
                XPTable.Models.Cell functionCell = new XPTable.Models.Cell(" " + baseObject.FunctionName);
                row.Cells.Add(functionCell);

                // Row Color & Object Association
                // ==============================
                if (baseObject is MemOpAllocation)
                {
                    // Allocation
                    memObj   = (MemOpAllocation)baseObject;
                    rowColor = Color.Blue;
                }
                else if (baseObject is MemOpFree)
                {
                    // Deallocation
                    if (baseObject.Link != null)
                    {
                        memObj = (MemOpAllocation)baseObject.Link;
                    }
                    else
                    {
                        memObj = null;
                    }
                    rowColor = Color.Green;
                }
                else if (baseObject is MemOpReallocation)
                {
                    // Reallocation
                    if (baseObject.Link != null)
                    {
                        memObj = (MemOpAllocation)baseObject.Link;
                    }
                    else
                    {
                        memObj = null;
                    }
                    rowColor = Color.Purple;
                }

                // Allocation size
                // ===============
                string allocationSize = "???";
                if (memObj != null)
                {
                    allocationSize = memObj.AllocationSize.ToString();
                }
                row.Cells.Add(new XPTable.Models.Cell(allocationSize + "  "));

                // Heap size
                // =========
                row.Cells.Add(new XPTable.Models.Cell(baseObject.HeapSize.ToString() + "  "));

                // Associated object
                // =================
                MemOpAllocation symbolObject = memObj;
                if (memObj != null && baseObject.Link != null)
                {
                    // If we have an associated link item, we can connect the two items together
                    string associatedText = string.Empty;
                    if (baseObject.IsAllocationType)
                    {
                        associatedText = "Free'd by op #:  " + baseObject.Link.OperationIndex.ToString("d5");
                    }
                    else if (baseObject.IsReallocationType)
                    {
                        associatedText = "First alloc'd by op #: " + baseObject.Link.OperationIndex.ToString("d5");
                        symbolObject   = (baseObject.Link as MemOpAllocation);
                    }
                    else
                    {
                        associatedText = "Alloc'd by op #: " + baseObject.Link.OperationIndex.ToString("d5");
                    }

                    // We store the object with the cell so that we can handle hyperlinks between
                    // associated objects.
                    XPTable.Models.Cell associatedCell = new XPTable.Models.Cell(associatedText);
                    associatedCell.Tag = baseObject;

                    // Make it look like a hyperlink
                    associatedCell.Font = new Font(iGrid.Font.FontFamily.Name, iGrid.Font.SizeInPoints, System.Drawing.FontStyle.Underline);

                    // Add the cell to the row
                    row.Cells.Add(associatedCell);
                }
                else
                {
                    if (baseObject.IsAllocationType)
                    {
                        if (memObj != null)
                        {
                            symbolObject = memObj;
                        }

                        rowColor = Color.Red;
                        row.Font = new System.Drawing.Font(iGrid.Font.FontFamily.Name, iGrid.Font.SizeInPoints, System.Drawing.FontStyle.Regular);
                        row.Cells.Add(new XPTable.Models.Cell("Object never free'd!"));
                    }
                    else
                    {
                        row.Cells.Add(new XPTable.Models.Cell("???!"));
                    }
                }

                // Set row color
                // =============
                row.ForeColor = rowColor;

                // Add row
                // =======
                iGrid.TableModel.Rows.Add(row);

                // Event handling
                // ==============
                if (i % 100 != 0)
                {
                    Application.DoEvents();
                }
                lock (this)
                {
                    if (iStopPopulatingGrid)
                    {
                        break;
                    }
                }
            }

            // If no items, then dim table
            iGrid.Enabled = (count > 0);
            iGrid.EndUpdate();
        }
        private void PrepareMemoryAnalysisData()
        {
            try
            {
                Cursor.Current    = Cursors.WaitCursor;
                iListView.Enabled = false;

                long totalAllocCount = 0;
                long totalFreeCount  = 0;
                long totalAllocSize  = 0;
                long totalFreeSize   = 0;
                long totalNetSize    = 0;

                // Ensure that each allocation-symbol is added to the symbol listbox
                MemObjStatisticalData data = iParser.Data;
                //
                iListView.BeginUpdate();
                int count = data.CollectionCount;
                for (int i = 0; i < count; i++)
                {
                    MemObjStatisticalCollection collection = data.CollectionAt(i);
                    if (collection.Count > 0)
                    {
                        System.Diagnostics.Debug.Assert(collection[0] is MemOpAllocation);
                        MemOpAllocation memObj = (MemOpAllocation)collection[0];
                        //
                        long allocCount   = collection.AllocationCount;
                        long freeCount    = collection.DeallocationCount;
                        long allocSize    = collection.TotalAmountOfAllocatedMemory;
                        long freeSize     = collection.TotalAmountOfDeallocatedMemory;
                        long netAllocSize = collection.TotalMemoryAllocatedButNotFreed;
                        //
                        ListViewItem item = new ListViewItem("");
                        item.Tag = collection;
                        item.SubItems.Add(allocCount.ToString());
                        item.SubItems.Add(freeCount.ToString());
                        item.SubItems.Add(allocSize.ToString());
                        item.SubItems.Add(freeSize.ToString());
                        item.SubItems.Add(netAllocSize.ToString());
                        string symbolText = "Unknown";
                        if (memObj.LinkRegisterSymbol != null && memObj.LinkRegisterSymbol.Symbol != null)
                        {
                            symbolText = memObj.LinkRegisterSymbol.Symbol.ToString();
                        }
                        item.SubItems.Add(symbolText);
                        iListView.Items.Add(item);

                        // Update totals
                        totalAllocCount += allocCount;
                        totalFreeCount  += freeCount;
                        totalAllocSize  += allocSize;
                        totalFreeSize   += freeSize;
                        totalNetSize    += netAllocSize;
                    }

                    if (count % 100 != 0)
                    {
                        Application.DoEvents();
                    }
                }
                iListView.EndUpdate();

                // Make the first item selected
                if (iListView.Items.Count > 0 && iListView.SelectedIndices.Count == 0)
                {
                    // Add total item
                    iListView.Items.Add(new ListViewItem(""));
                    //
                    ListViewItem totalItem = new ListViewItem("Totals:");
                    totalItem.SubItems.Add(totalAllocCount.ToString());
                    totalItem.SubItems.Add(totalFreeCount.ToString());
                    totalItem.SubItems.Add(totalAllocSize.ToString());
                    totalItem.SubItems.Add(totalFreeSize.ToString());
                    totalItem.SubItems.Add(totalNetSize.ToString());
                    totalItem.SubItems.Add("");
                    iListView.Items.Add(totalItem);
                    //
                    iListView.Items[0].Selected = true;
                    iListView.Select();
                }
            }
            finally
            {
                Cursor.Current    = Cursors.Default;
                iListView.Enabled = true;
                iListView.Select();
            }
        }