public void SetFirstSnapshot(QueriedMemorySnapshot snapshot)
        {
            if (snapshot == null)
            {
                Debug.LogError("UIState.SetFirstSnapshot can't be called with null, if you meant to clear the open snapshots, call ClearAllOpenSnapshots");
                return;
            }
            history.Clear();
            if (FirstMode != null)
            {
                if (SecondMode != null)
                {
                    SecondMode.Clear();
                }
                SecondMode = FirstMode;
            }
            FirstMode = new SnapshotMode(FormattingOptions.ObjectDataFormatter, snapshot);

            // Make sure that the first mode is shown and that ModeChanged (fired by ShownMode if set to something different) is fired.
            if (CurrentViewMode != ViewMode.ShowFirst)
            {
                CurrentViewMode = ViewMode.ShowFirst;
            }
            else
            {
                ModeChanged(CurrentMode, CurrentViewMode);
            }
            ClearDiffMode();
        }
 protected SnapshotMode(SnapshotMode copy)
     : base(copy)
 {
     m_RawSnapshot   = copy.m_RawSnapshot;
     m_RawSchema     = copy.m_RawSchema;
     ViewSchema      = copy.ViewSchema;
     SchemaToDisplay = copy.SchemaToDisplay;
     m_RawSchema.formatter.BaseFormatter.PrettyNamesOptionChanged += UpdateTableSelectionNames;
 }
            void SetSnapshot(ObjectDataFormatter objectDataFormatter, QueriedMemorySnapshot snapshot)
            {
                if (snapshot == null)
                {
                    m_RawSnapshot   = null;
                    m_RawSchema     = null;
                    SchemaToDisplay = null;
                    UpdateTableSelectionNames();
                    return;
                }

                m_RawSnapshot = snapshot;

                ProgressBarDisplay.ShowBar(string.Format("Opening snapshot: {0}", System.IO.Path.GetFileNameWithoutExtension(snapshot.GetReader().FilePath)));

                var cachedSnapshot = new CachedSnapshot(snapshot);

                using (s_CrawlManagedData.Auto())
                {
                    var crawling = Crawler.Crawl(cachedSnapshot);
                    crawling.MoveNext(); //start execution

                    var   status          = crawling.Current as EnumerationStatus;
                    float progressPerStep = 1.0f / status.StepCount;
                    while (crawling.MoveNext())
                    {
                        ProgressBarDisplay.UpdateProgress(status.CurrentStep * progressPerStep, status.StepStatus);
                    }
                }
                ProgressBarDisplay.ClearBar();

                m_RawSchema = new RawSchema();
                m_RawSchema.SetupSchema(cachedSnapshot, objectDataFormatter);

                SchemaToDisplay = m_RawSchema;
                if (k_DefaultViewFilePath.Length > 0)
                {
                    Database.View.ViewSchema.Builder builder = null;
                    builder = Database.View.ViewSchema.Builder.LoadFromXMLFile(k_DefaultViewFilePath);

                    if (builder != null)
                    {
                        ViewSchema = builder.Build(m_RawSchema);
                        if (ViewSchema != null)
                        {
                            SchemaToDisplay = ViewSchema;
                        }
                    }
                }

                UpdateTableSelectionNames();
            }
        public CachedSnapshot(QueriedMemorySnapshot s)
        {
            var vmInfo = s.virtualMachineInformation;

            if (!VMTools.ValidateVirtualMachineInfo(vmInfo))
            {
                throw new UnityException("Invalid VM info. Snapshot file is corrupted.");
            }

            virtualMachineInformation = vmInfo;
            packedMemorySnapshot      = s;
            m_SnapshotVersion         = s.version;
            nativeAllocationSites     = new NativeAllocationSiteEntriesCache(s.nativeAllocationSites);
            typeDescriptions          = new TypeDescriptionEntriesCache(s.typeDescriptions);
            nativeTypes            = new NativeTypeEntriesCache(s.nativeTypes);
            nativeRootReferences   = new NativeRootReferenceEntriesCache(s.nativeRootReferences);
            nativeObjects          = new NativeObjectEntriesCache(s.nativeObjects);
            nativeMemoryRegions    = new NativeMemoryRegionEntriesCache(s.nativeMemoryRegions);
            nativeMemoryLabels     = new NativeMemoryLabelEntriesCache(s.nativeMemoryLabels);
            nativeCallstackSymbols = new NativeCallstackSymbolEntriesCache(s.nativeCallstackSymbols);
            nativeAllocations      = new NativeAllocationEntriesCache(s.nativeAllocations);
            managedStacks          = new ManagedMemorySectionEntriesCache(s.managedStacks);
            managedHeapSections    = new ManagedMemorySectionEntriesCache(s.managedHeapSections);
            gcHandles         = new GCHandleEntriesCache(s.gcHandles);
            fieldDescriptions = new FieldDescriptionEntriesCache(s.fieldDescriptions);
            connections       = new ConnectionEntriesCache(s, HasConnectionOverhaul);

            SortedNativeRegionsEntries = new SortedNativeMemoryRegionEntriesCache(this);
            SortedManagedStacksEntries = new SortedManagedMemorySectionEntriesCache(managedStacks);
            SortedManagedHeapEntries   = new SortedManagedMemorySectionEntriesCache(managedHeapSections);

            SortedManagedObjects    = new SortedManagedObjectsCache(this);
            SortedNativeAllocations = new SortedNativeAllocationsCache(this);
            SortedNativeObjects     = new SortedNativeObjectsCache(this);

            CrawledData = new ManagedData(gcHandles.Count, connections.Count);

            typeDescriptions.InitSecondaryItems(this);
            nativeObjects.InitSecondaryItems();
            nativeObjects.InitSecondaryItems(this);
        }
 public SnapshotMode(ObjectDataFormatter objectDataFormatter, QueriedMemorySnapshot snapshot)
 {
     objectDataFormatter.PrettyNamesOptionChanged += UpdateTableSelectionNames;
     SetSnapshot(objectDataFormatter, snapshot);
 }
            public ConnectionEntriesCache(QueriedMemorySnapshot snap, bool connectionsNeedRemaping)
            {
                var ss = snap.connections;

                Count   = ss.GetNumEntries();
                dataSet = new SoaDataSet(Count, kCacheEntrySize);
#if UNITY_2019_3_OR_NEWER
                if (connectionsNeedRemaping)
                {
                    var fromAPIArr = new int[Count];
                    ss.from.GetEntries(0, (uint)Count, ref fromAPIArr);
                    var toAPIArr = new int[Count];
                    ss.to.GetEntries(0, (uint)Count, ref toAPIArr);
                    var instanceIDArr = new int[snap.nativeObjects.instanceId.GetNumEntries()];
                    snap.nativeObjects.instanceId.GetEntries(0, snap.nativeObjects.instanceId.GetNumEntries(), ref instanceIDArr);
                    var gchandlesIndexArr = new int[snap.nativeObjects.gcHandleIndex.GetNumEntries()];
                    snap.nativeObjects.gcHandleIndex.GetEntries(0, snap.nativeObjects.gcHandleIndex.GetNumEntries(), ref gchandlesIndexArr);

                    Dictionary <int, int> instanceIDToIndex         = new Dictionary <int, int>();
                    Dictionary <int, int> instanceIDToGcHandleIndex = new Dictionary <int, int>();

                    for (int i = 0; i < instanceIDArr.Length; ++i)
                    {
                        if (gchandlesIndexArr[i] != -1)
                        {
                            instanceIDToGcHandleIndex.Add(instanceIDArr[i], gchandlesIndexArr[i]);
                        }
                        instanceIDToIndex.Add(instanceIDArr[i], i);
                    }

                    var   gcHandlesCount = snap.gcHandles.GetNumEntries();
                    int[] fromIndices    = new int[Count + instanceIDToGcHandleIndex.Count];
                    int[] toIndices      = new int[fromIndices.Length];

                    for (long i = 0; i < Count; ++i)
                    {
                        fromIndices[i] = (int)(gcHandlesCount + instanceIDToIndex[fromAPIArr[i]]);

                        //some native objects might have references to other native objects that are currently getting deleted or have been deleted
                        int instanceIDIDX = -1;
                        if (!instanceIDToIndex.TryGetValue(toAPIArr[i], out instanceIDIDX))
                        {
                            toIndices[i] = instanceIDIDX;
                        }
                        else
                        {
                            toIndices[i] = (int)(gcHandlesCount + instanceIDIDX);
                        }
                    }


                    var enumerator = instanceIDToGcHandleIndex.GetEnumerator();
                    for (long i = Count; i < fromIndices.Length; ++i)
                    {
                        enumerator.MoveNext();
                        fromIndices[i] = (int)(gcHandlesCount + instanceIDToIndex[enumerator.Current.Key]);
                        toIndices[i]   = enumerator.Current.Value;
                    }

                    from = DataArray.MakeCache(dataSet, DataSourceFromAPI.ApiToDatabase(fromIndices));
                    to   = DataArray.MakeCache(dataSet, DataSourceFromAPI.ApiToDatabase(toIndices));
                }
                else
#endif
                {
                    from = DataArray.MakeCache(dataSet, DataSourceFromAPI.ApiToDatabase(ss.from));
                    to   = DataArray.MakeCache(dataSet, DataSourceFromAPI.ApiToDatabase(ss.to));
                }
            }
 public QueriedMemorySnapshot LoadSnapshot()
 {
     return(QueriedMemorySnapshot.Load(FileInfo.FullName));
 }