Пример #1
0
        private int CollectionIndex(MemObjRegionalCollection aCollection)
        {
            int ret   = -1;
            int index = 0;
            //
            int count = iListView.Items.Count;

            foreach (ListViewItem item in iListView.Items)
            {
                if (item.Tag != null)
                {
                    MemObjRegionalCollection col = (MemObjRegionalCollection)item.Tag;
                    if (col == aCollection)
                    {
                        index = ret;
                        break;
                    }
                }
                else
                {
                    break;
                }

                ++index;
            }
            //
            return(index);
        }
Пример #2
0
        private void iTable_CellClick(object sender, XPTable.Events.CellMouseEventArgs e)
        {
            if (e.Cell.Tag is MemOpBase)
            {
                // Get the object
                MemOpBase baseObject = (MemOpBase)e.Cell.Tag;
                System.Diagnostics.Debug.Assert(baseObject.Link != null);

                // Get the current collection
                if (iListView.SelectedIndices.Count > 0 && !iPreparingGrid)
                {
                    ListViewItem listItem = iListView.SelectedItems[0];
                    if (listItem.Tag != null && listItem.Tag is MemObjRegionalCollection)
                    {
                        MemObjRegionalCollection collection = (MemObjRegionalCollection)listItem.Tag;

                        // Get the associated (linked) collection
                        int       collectionIndex;
                        int       itemIndex;
                        MemOpBase linkedItem;
                        MemObjRegionalCollection linkedCollection = iParser.Data.CollectionByOperationIndex(baseObject.Link.OperationIndex,
                                                                                                            baseObject.Link.Class,
                                                                                                            out linkedItem,
                                                                                                            out collectionIndex,
                                                                                                            out itemIndex);

                        // Did we find a linked item?
                        if (linkedCollection != null && linkedItem != null)
                        {
                            // Select the correct list item
                            if (collection != linkedCollection)
                            {
                                // We need to jump to a different collection...
                                if (linkedCollection.RegionStart.MatchedRegionText || !iParser.Options.MarkerOperationsOutsideRegionToBeIgnored)
                                {
                                    if (iParser.Options.MarkerOperationsOutsideRegionToBeIgnored)
                                    {
                                        collectionIndex = CollectionIndex(linkedCollection);
                                    }
                                    iListView.Items[iListView.SelectedIndices[0]].Selected = false;
                                    iListView.Items[collectionIndex].Selected = true;
                                    iListView.Select();
                                }
                            }

                            // Select it
                            iTable.TableModel.Selections.Clear();
                            iTable.TableModel.Selections.AddCell(itemIndex, 6);
                            iTable.EnsureVisible(itemIndex, 6);
                            iTable.Select();
                        }
                    }
                }
            }
        }
Пример #3
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();
                }
            }
        }
Пример #4
0
        private void PrepareListView()
        {
            try
            {
                iListView.Enabled = false;
                Cursor.Current    = Cursors.WaitCursor;

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

                // Ensure that each allocation-symbol is added to the symbol listbox
                MemObjRegionalData data = iParser.Data;
                //
                iListView.BeginUpdate();
                int count = data.Count;
                for (int i = 0; i < count; i++)
                {
                    MemObjRegionalCollection collection = data[i];
                    //
                    if (collection.RegionStart.MatchedRegionText || !iParser.Options.MarkerOperationsOutsideRegionToBeIgnored)
                    {
                        long allocCount  = collection.AllocationCount;
                        long freeCount   = collection.DeallocationCount;
                        long allocSize   = collection.TotalAmountOfAllocatedMemory;
                        long deallocSize = collection.TotalAmountOfDeallocatedMemory;
                        long netSize     = collection.TotalMemoryAllocatedButNotFreed;
                        //
                        ListViewItem item = new ListViewItem((i + 1).ToString("d8"));
                        item.SubItems.Add(collection.RegionStart.LineNumber.ToString("d8"));
                        item.SubItems.Add(allocCount.ToString());
                        item.SubItems.Add(freeCount.ToString());
                        item.SubItems.Add(allocSize.ToString());
                        item.SubItems.Add(deallocSize.ToString());
                        item.SubItems.Add(netSize.ToString());
                        item.SubItems.Add(collection.RegionStart.RegionText);
                        item.Tag = collection;
                        iListView.Items.Add(item);

                        // Update totals
                        totalAllocCount  += allocCount;
                        totalFreeCount   += freeCount;
                        totalAllocSize   += allocSize;
                        totalDeallocSize += deallocSize;
                        totalNetSize     += netSize;
                    }
                    //
                    if (count % 100 != 0)
                    {
                        Application.DoEvents();
                    }
                }

                // 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("");
                    totalItem.SubItems.Add(totalAllocCount.ToString());
                    totalItem.SubItems.Add(totalFreeCount.ToString());
                    totalItem.SubItems.Add(totalAllocSize.ToString());
                    totalItem.SubItems.Add(totalDeallocSize.ToString());
                    totalItem.SubItems.Add(totalNetSize.ToString());
                    totalItem.SubItems.Add("");
                    iListView.Items.Add(totalItem);
                    //
                    iListView.Items[0].Selected = true;
                    iListView.Select();
                }

                iListView.EndUpdate();
            }
            finally
            {
                Cursor.Current    = Cursors.Default;
                iListView.Enabled = true;
                iListView.Select();
            }
        }