public MemOpBase ItemByAddressAndOperationIndex(uint aCellAddress, int aOperationIndex, TClass aClass, out int aIndex) { aIndex = -1; MemOpBase ret = null; // for (int i = iItems.Count - 1; i >= 0; i--) { MemOpBase item = iItems[i]; // if (item.CellAddress == aCellAddress && item.OperationIndex == aOperationIndex) { if (aClass == TClass.ENotApplicable) { aIndex = i; ret = item; break; } else if (item.Class == aClass) { aIndex = i; ret = item; break; } } } // return(ret); }
private void AddToCollection(MemOpBase aItem) { // Add the item to our master list... iAllItems.Add(aItem); aItem.OperationIndex = iAllItems.Count; // If the start region marker hasn't been initialised, it means // that the object operation took place outside of an allocation if (iCurrentCollection == null || iCurrentCollection.RegionStart.Initialised == false) { if (iCurrentCollection == null) { iCurrentCollection = new MemObjRegionalCollection(); } // In this case, we set the start line number to the line upon // which the operation took place. iCurrentCollection.RegionStart.LineNumber = aItem.LineNumber; iCurrentCollection.RegionStart.RegionText = KOperationOutsideOfRegionText; } // Associate the item with this collection aItem.Collection = iCurrentCollection; iCurrentCollection.Add(aItem); }
public MemObjStatisticalCollection CollectionByCellAddressSearchForwards(uint aCellAddress, TClass aClass) { MemObjStatisticalCollection ret = null; // int count = iAllItems.Count; for (int i = 0; i < count; i++) { MemOpBase item = (MemOpBase)iAllItems[i]; // if (item.CellAddress == aCellAddress) { if (aClass == TClass.ENotApplicable) { // Found the item, now locate its collection... ret = CollectionBySymbol(item); break; } else if (aClass == item.Class) { // Found the item, now locate its collection... ret = CollectionBySymbol(item); break; } } } // return(ret); }
public MemObjRegionalCollection CollectionByCellAddress(long aCellAddress, TClass aClass, out int aCollectionIndex) { aCollectionIndex = -1; int itemIndex = -1; MemOpBase item = null; return(CollectionByCellAddress(aCellAddress, aClass, out item, out aCollectionIndex, out itemIndex)); }
public MemOpBase this[int aIndex] { get { MemOpBase item = (MemOpBase)iItems[aIndex]; return(item); } }
public void Add(MemOpBase aItem, bool aDiscardAllocAndFreedMatchingCells) { #region When deallocating, search for original alloc and link items... // 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 throwAwayObject = false; if (aItem.IsAllocationType == false) { int count = iAllItems.Count; for (int i = count - 1; i >= 0; i--) { MemOpBase item = (MemOpBase)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.. //System.Diagnostics.Debug.Assert( item.IsAllocationType == true ); - User::Realloc screwing things up? if (aDiscardAllocAndFreedMatchingCells) { // Can ignore both cells. First remove teh previous allocation cell. iAllItems.RemoveAt(i); // We don't even add aItem to the 'all items' container. // However, we still need to remove the linked allocation from it's container. if (item.Collection != null) { MemObjRegionalCollection collectionForAllocation = (MemObjRegionalCollection)item.Collection; int colCount = collectionForAllocation.Count; collectionForAllocation.RemoveByCellAddress(item); // Make sure we really removed it. System.Diagnostics.Debug.Assert(collectionForAllocation.Count == colCount - 1); // We don't want to log this 'free' operation since it perfectly // matched an allocation. throwAwayObject = true; } } else { item.Link = aItem; aItem.Link = item; } break; } } } #endregion // Add the item to our master list... if (!throwAwayObject) { AddToCollection(aItem); } }
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 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(); } } } } }
public void RemovePriorOperation(MemOpBase aItem) { /* * if ( aItem.CellAddress == 0xc8036684 ) * { * int x = 0; * x++; * } */ iAllItems.Remove(aItem); }
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; } }
public void AddToCollection(MemOpBase aItem, SymbolLib.Generics.GenericSymbol aSymbol, uint aLinkRegisterAddress) { MemObjStatisticalCollection collection = CollectionBySymbol(aSymbol, aLinkRegisterAddress); if (collection == null) { // Make a new collection collection = new MemObjStatisticalCollection(); iCollections.Add(collection); } collection.Add(aItem); }
private void iGrid_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.C && e.Control && iListView.SelectedIndices.Count > 0) { XPTable.Models.Row[] rows = iGrid.SelectedItems; if (rows.Length > 0 && rows[0].Tag != null && rows[0].Tag is MemOpBase) { MemOpBase op = rows[0].Tag as MemOpBase; // Clipboard.SetDataObject(op.ToString(), true); e.Handled = true; } } }
public bool RemoveByCellAddress(MemOpBase aItem) { int index; bool ret = false; // if (ItemByAddress(aItem.CellAddress, aItem.Class, out index) != null) { iItems.RemoveAt(index); ret = true; } // return(ret); }
public MemOpBase ItemByLineNumber(long aLineNumber) { int count = iAllItems.Count; for (int i = count - 1; i >= 0; i--) { MemOpBase item = (MemOpBase)iAllItems[i]; if (item.LineNumber == aLineNumber) { return(item); } } return(null); }
protected void ParseCommonKernel(MemOpBase aOperation, ref string aLine, MemAnalysisParserPrefixesBase aPrefixes) { string line = aLine; // if (line.IndexOf(aPrefixes.CellAddress) >= 0) { PrefixParser.SkipPrefix(aPrefixes.CellAddress, ref line); aOperation.CellAddress = PrefixParser.ReadUint(ref line); } if (line.IndexOf(aPrefixes.HeapSize) >= 0) { PrefixParser.SkipPrefix(aPrefixes.HeapSize, ref line); aOperation.HeapSize = PrefixParser.ReadUint(ref line); } if (line.IndexOf(aPrefixes.ChunkSize) >= 0) { PrefixParser.SkipPrefix(aPrefixes.ChunkSize, ref line); aOperation.ChunkSize = PrefixParser.ReadUint(ref line); } if (line.IndexOf(aPrefixes.LinkRegister) >= 0) { PrefixParser.SkipPrefix(aPrefixes.LinkRegister, ref line); aOperation.LinkRegisterAddress = PrefixParser.ReadUint(ref line); } if (line.IndexOf(aPrefixes.CellSize) >= 0) { PrefixParser.SkipPrefix(aPrefixes.CellSize, ref line); aOperation.CellSize = PrefixParser.ReadUint(ref line); } if (line.IndexOf(aPrefixes.AllocNumber) >= 0) { PrefixParser.SkipPrefix(aPrefixes.AllocNumber, ref line); try { aOperation.AllocationNumber = PrefixParser.ReadUint(ref line); } catch (Exception) { } } if (line.IndexOf(aPrefixes.VTable) >= 0) { PrefixParser.SkipPrefix(aPrefixes.VTable, ref line); aOperation.VTable = PrefixParser.ReadUint(ref line); } }
public MemOpBase PriorOperationByAllocationNumber(uint aAllocNumber) { MemOpBase ret = null; // for (int i = AllPriorOperationsCount - 1; i >= 0; i--) { MemOpBase op = AllPriorOperations[i]; // if (op.AllocationNumber == aAllocNumber) { ret = op; break; } } // return(ret); }
public void RemoveFromCollection(MemOpBase aItem) { int count = iCollections.Count; for (int i = count - 1; i >= 0; i--) { MemObjStatisticalCollection collection = (MemObjStatisticalCollection)iCollections[i]; System.Diagnostics.Debug.Assert(collection.Count > 0 || collection == iNullSymbolCollection); if (collection.Remove(aItem)) { // Remove the collection as well (if its empty) if (collection.Count == 0) { iCollections.RemoveAt(i); } break; } } }
public MemOpBase ItemByAddress(long aCellAddress, out int aIndex) { aIndex = -1; MemOpBase ret = null; int count = iItems.Count; // for (int i = count - 1; i >= 0; i--) { MemOpBase item = (MemOpBase)iItems[i]; if (item.CellAddress == aCellAddress) { aIndex = i; ret = item; break; } } // return(ret); }
protected override void HandleFilteredLine(string aLine) { if (aLine != null) { MemOpBase operation = null; MemOpFnBase function = null; // bool handled = Prefixes.MatchesPrefix(ref aLine, out function); if (handled && function != null) { operation = function.Parse(ref aLine, Prefixes); if (operation != null) { // Finalise it operation.LineNumber = System.Convert.ToUInt32(LineNumber); operation.Finalise(SymbolManager); // Notify switch (function.Class) { case MemAnalysisLib.MemoryOperations.Class.TClass.EAllocation: HandleOpAllocation(operation as MemOpAllocation); break; case MemAnalysisLib.MemoryOperations.Class.TClass.EDeallocation: HandleOpFree(operation as MemOpFree); break; case MemAnalysisLib.MemoryOperations.Class.TClass.EReallocation: HandleOpReallocation(operation as MemOpReallocation); break; default: break; } } } } }
public MemOpBase ItemByOperationIndex(long aOpIndex, TClass aClass, out int aIndex) { aIndex = -1; MemOpBase ret = null; int count = iItems.Count; // for (int i = count - 1; i >= 0; i--) { MemOpBase item = (MemOpBase)iItems[i]; if (item.OperationIndex == aOpIndex) { if (aClass == TClass.ENotApplicable || item.Class == aClass) { aIndex = i; ret = item; break; } } } // return(ret); }
private void iGrid_CellClick(object sender, XPTable.Events.CellMouseEventArgs e) { if (e.Cell.Tag != null && e.Cell.Tag is MemOpBase) { // Get the object & collection MemOpBase currentObject = (MemOpBase)e.Cell.Tag; MemObjStatisticalCollection collection = (MemObjStatisticalCollection)currentObject.Collection; // If we have a linked item, then we'll attempt to show it if (currentObject.Link != null) { MemOpBase linkedOp = currentObject.Link; // We know that the linked item should be in the same collection - so search for it. int rowIndex = 0; foreach (XPTable.Models.Row row in iGrid.TableModel.Rows) { // The first row's tag has been setup to point to a MemOpBase object for the entire row. MemOpBase rowTagEntry = (MemOpBase)row.Tag; if (rowTagEntry.CellAddress == linkedOp.CellAddress && rowTagEntry.OperationIndex == linkedOp.OperationIndex && rowTagEntry.AllocationNumber == linkedOp.AllocationNumber && rowTagEntry != currentObject) { // This is the one to focus to. iGrid.TableModel.Selections.SelectCell(rowIndex, 5); iGrid.EnsureVisible(rowIndex, 5); iGrid.Select(); break; } // No match... ++rowIndex; } } } }
public MemOpBase AllItemAt(int aIndex) { MemOpBase item = (MemOpBase)iAllItems[aIndex]; return(item); }
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(); }
public override void Process(MemOpBase aItem, CollectionManager aCollectionManager) { if (aItem.CellAddress == 0xc8099f8c) { int x = 0; x++; } // (1) Alloc, SafeRealloc // // [KMEM] OKA - C: 0xc801a65c, HS: 29096, HCS: 53128, LR: 0x800b82f4, CS: 4, AS: 4, AN: 93 // [KMEM] OKSR - C: 0xc801a65c, HS: 29096, HCS: 53128, LR: 0x800aebdc, AS: 4, AN: 93, OC: 0x00000000, OCS: 0, OCAN: 0, VT: 0x00000000 // // // (2) Realloc, SafeRealloc // [KMEM] OKR - C: 0xc801ae1c, HS: 33656, HCS: 53128, LR: 0x800b82d4, AS: 12, AN: 106, MD: 1, OC: 0xc801ae1c, OCS: 12, OCAN: 106, VT: 0xc801a688 // [KMEM] OKSR - C: 0xc801ae1c, HS: 33656, HCS: 53128, LR: 0x800aebdc, AS: 12, AN: 106, OC: 0xc801ae1c, OCS: 12, OCAN: 106, VT: 0xc801a688 // ... // [KMEM] OKR - C: 0xc822ee8c, HS: 1672036, HCS: 2236296, LR: 0x800b83c8 [ Kern::SafeReAlloc(void*&, int, int) ], CS: 660, AS: 652, AN: 99936, MD: 0, OC: 0xc822ee8c, OCS: 660, OCAN: 99936, VT: 0xc80131e8 // [KMEM] OKSR - C: 0xc822ee8c, HS: 1672036, HCS: 2236296, LR: 0x800adc7c [ DObjectCon::Remove(DObject*) ], CS: 660, AS: 652, AN: 99936, OC: 0xc822ee8c, OCS: 660, OCAN: 99936, VT: 0xc80131e8 // // // (3) Alloc, Free, SafeRealloc // // [KMEM] OKA - C: 0xc801a744, HS: 29268, HCS: 53128, LR: 0x800b82f4, CS: 4, AS: 4, AN: 98 // [KMEM] OKSR - C: 0xc801a744, HS: 29268, HCS: 53128, LR: 0x800aebdc, AS: 4, AN: 98, OC: 0x00000000, OCS: 0, OCAN: 0, VT: 0x00000000 // ... // [KMEM] OKA - C: 0xc801ae1c, HS: 30932, HCS: 53128, LR: 0x800b82f4, CS: 12, AS: 8, AN: 106 // [KMEM] OKF - C: 0xc801a744, HS: 30928, HCS: 53128, LR: 0x800b836c, CS: 4, AN: 98, VT: 0xc801a688 // [KMEM] OKSR - C: 0xc801ae1c, HS: 30928, HCS: 53128, LR: 0x800aebdc, AS: 8, AN: 106, OC: 0xc801a744, OCS: 4, OCAN: 98, VT: 0xc801a688 MemOpBase lastOpByAllocNumber = aCollectionManager.PriorOperationByAllocationNumber(aItem.AllocationNumber); MemOpReallocation op = (MemOpReallocation)aItem; if (lastOpByAllocNumber != null) { if (lastOpByAllocNumber.CellAddress == op.CellAddress && lastOpByAllocNumber.Class == TClass.EAllocation && op.OriginalAddress == 0) { // 1) Alloc, SafeRealloc => dump alloc aCollectionManager.RemoveFromCollection(lastOpByAllocNumber); aCollectionManager.RemovePriorOperation(lastOpByAllocNumber); aCollectionManager.AddToCollection(op, op.LinkRegisterSymbol, op.LinkRegisterAddress); aCollectionManager.AddNewPriorOperation(op); } else if (lastOpByAllocNumber.Class == TClass.EReallocation && lastOpByAllocNumber.CellAddress == op.CellAddress) { // 2) Realloc, SafeRealloc => dump realloc aCollectionManager.RemoveFromCollection(lastOpByAllocNumber); aCollectionManager.RemovePriorOperation(lastOpByAllocNumber); // Also, it's possible that this is just a no-op. For example, this pattern can occur when removing // an object from a DObjectCon, in which case the DObjectCon code requests that the cell be shrunk in size. // // If there is no cell growth, then we shouldn't bother saving the operation. int impact = (int)op.AllocationSize - (int)op.OriginalAllocationSize; if (impact > 0) { aCollectionManager.AddToCollection(op, op.LinkRegisterSymbol, op.LinkRegisterAddress); aCollectionManager.AddNewPriorOperation(op); } } else { // Checking for scenario (3) // // lastOpByAllocNumber will correspond to the 'alloc' operation. if (lastOpByAllocNumber.Class == TClass.EAllocation && lastOpByAllocNumber.CellAddress == op.CellAddress) // Satisfies linkage between OKSR and OKA { // We need to find out what the prior op was for the original cell allocation number. // This should point to the 'free' operation. MemOpBase freeOp = aCollectionManager.PriorOperationByAllocationNumber(op.OriginalAllocationNumber); // If we're throwing away matching allocated & subsequently freed cells, then freeOp will be null... if (freeOp == null || (freeOp.Class == TClass.EDeallocation && freeOp.CellAddress == op.OriginalAddress)) { // (3) Alloc, Free, SafeRealloc => dump alloc and free! // Remove alloc, which is replaced by our new SafeRealloc entry aCollectionManager.RemovePriorOperation(lastOpByAllocNumber); aCollectionManager.RemoveFromCollection(lastOpByAllocNumber); // Remove free for the old SafeRealloc heap cell if (freeOp != null) { aCollectionManager.RemovePriorOperation(freeOp); aCollectionManager.RemoveFromCollection(freeOp); // We may also need to remove a prior SafeRealloc that uses the same heap cell MemOpBase safeReallocForDeletedCell = aCollectionManager.PriorOperationByAllocationNumber(freeOp.AllocationNumber); if (safeReallocForDeletedCell.Class == TClass.EReallocation && safeReallocForDeletedCell.CellAddress == freeOp.CellAddress) { // Remove prior realloc associated with the old heap cell aCollectionManager.RemovePriorOperation(safeReallocForDeletedCell); aCollectionManager.RemoveFromCollection(safeReallocForDeletedCell); } } // Now add our new SafeRealloc entry to the master list aCollectionManager.AddToCollection(op, op.LinkRegisterSymbol, op.LinkRegisterAddress); aCollectionManager.AddNewPriorOperation(op); } } } } }
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); } }
public MemObjRegionalCollection CollectionByCellAddress(long aCellAddress, TClass aClass, out MemOpBase aItem, out int aCollectionIndex, out int aItemIndex) { aItem = null; aCollectionIndex = -1; aItemIndex = -1; MemObjRegionalCollection ret = null; // First check whether the item is in the current collection (if we have one) if (iCurrentCollection != null) { aItem = iCurrentCollection.ItemByAddress(aCellAddress, aClass, out aItemIndex); if (aItem != null) { // Yes, it resides in the current collection... ret = iCurrentCollection; } } else { // Need to search the remaining collections. Must search backwards! int count = iCollections.Count; for (int i = count - 1; i >= 0; i--) { MemObjRegionalCollection collection = (MemObjRegionalCollection)iCollections[i]; aItem = collection.ItemByAddress(aCellAddress, aClass, out aItemIndex); if (aItem != null) { // Yes, its in this collection ret = collection; aCollectionIndex = i; break; } } } return(ret); }
public void AddNewPriorOperation(MemOpBase aItem) { iLastOperation = aItem; AllPriorOperations.Add(aItem); aItem.OperationIndex = AllPriorOperationsCount; }
public void Add(MemOpBase aItem) { iItems.Add(aItem); }
public virtual string ToString(MemOpBase aOperation) { string ret = string.Empty; return(ret); }