Example #1
0
        public V45Runtime(ClrInfo info, DataTarget dt, DacLibrary lib)
            : base(info, dt, lib)
        {
            if (!GetCommonMethodTables(ref _commonMTs))
            {
                throw new ClrDiagnosticsException("Could not request common MethodTable list.", ClrDiagnosticsException.HR.DacError);
            }

            if (!_commonMTs.Validate())
            {
                CanWalkHeap = false;
            }

            // Ensure the version of the dac API matches the one we expect.  (Same for both
            // v2 and v4 rtm.)
            byte[] tmp = new byte[sizeof(int)];

            if (!Request(DacRequests.VERSION, null, tmp))
            {
                throw new ClrDiagnosticsException("Failed to request dac version.", ClrDiagnosticsException.HR.DacError);
            }

            int v = BitConverter.ToInt32(tmp, 0);

            if (v != 9)
            {
                throw new ClrDiagnosticsException("Unsupported dac version.", ClrDiagnosticsException.HR.DacError);
            }
        }
Example #2
0
        public SOSHandleEnum(DacLibrary library, IntPtr pUnk)
            : base(library.OwningLibrary, ref IID_ISOSHandleEnum, pUnk)
        {
            ISOSHandleEnumVTable *vtable = (ISOSHandleEnumVTable *)_vtable;

            InitDelegate(ref _next, vtable->Next);
        }
Example #3
0
        protected override void InitApi()
        {
            if (_sos == null)
            {
                _sos = DacLibrary.GetSOSInterfaceNoAddRef();
            }

            Debug.Assert(_sos != null);
        }
Example #4
0
 internal DesktopRuntimeBase(ClrInfo info, DataTarget dt, DacLibrary lib)
     : base(info, dt, lib)
 {
     _heap        = new Lazy <DesktopGCHeap>(CreateHeap);
     _threads     = new Lazy <List <ClrThread> >(CreateThreadList);
     _appDomains  = new Lazy <DomainContainer>(CreateAppDomainList);
     _threadpool  = new Lazy <DesktopThreadPool>(CreateThreadPoolData);
     _moduleSizes = new Lazy <Dictionary <ulong, uint> >(() => _dataReader.EnumerateModules().ToDictionary(module => module.ImageBase, module => module.FileSize));
     _mscorlib    = new Lazy <ClrModule>(GetMscorlib);
 }
Example #5
0
        public ClrDataProcess(DacLibrary library, IntPtr pUnknown)
            : base(library?.OwningLibrary, IID_IXCLRDataProcess, pUnknown)
        {
            if (library is null)
            {
                throw new ArgumentNullException(nameof(library));
            }

            _library = library;
        }
Example #6
0
        public ClrStackWalk?CreateStackWalk(DacLibrary library, uint flags)
        {
            CreateStackWalkDelegate create = Marshal.GetDelegateForFunctionPointer <CreateStackWalkDelegate>(VTable.CreateStackWalk);

            if (!create(Self, flags, out IntPtr pUnk))
            {
                return(null);
            }

            GC.KeepAlive(create);
            return(new ClrStackWalk(library, pUnk));
        }
Example #7
0
        public ClrStackWalk CreateStackWalk(DacLibrary library, uint flags)
        {
            CreateStackWalkDelegate create = (CreateStackWalkDelegate)Marshal.GetDelegateForFunctionPointer(VTable->CreateStackWalk, typeof(CreateStackWalkDelegate));
            int hr = create(Self, flags, out IntPtr pUnk);

            if (hr != S_OK)
            {
                return(null);
            }

            return(new ClrStackWalk(library, pUnk));
        }
Example #8
0
        public RhRuntime(DataTargetImpl dt, DacLibrary lib)
            : base(dt, lib)
        {
            byte[] tmp = new byte[sizeof(int)];

            if (!Request(DacRequests.VERSION, null, tmp))
                throw new ClrDiagnosticsException("Failed to request dac version.", ClrDiagnosticsException.HR.DacError);

            m_dacRawVersion = BitConverter.ToInt32(tmp, 0);
            if (m_dacRawVersion != 10 && m_dacRawVersion != 11)
                throw new ClrDiagnosticsException("Unsupported dac version.", ClrDiagnosticsException.HR.DacError);
        }
Example #9
0
        public NativeRuntime(ModuleInfo module, DataTarget dt, DacLibrary lib)
        {
            Module      = module;
            DataTarget  = dt;
            SOSNative   = lib.GetInterface <SOSNative>(ref SOSNative.IID_ISOSNative);
            _dataReader = dt.DataReader;
            _modules    = dt.EnumerateModules().ToArray();

            if (SOSNative == null)
            {
                throw new ClrDiagnosticsException("Unsupported dac version.", ClrDiagnosticsException.HR.DacError);
            }
        }
Example #10
0
        /// <summary>
        /// Flushes the DAC cache.  This function <b>must</b> be called any time you expect to call the same function
        /// but expect different results.  For example, after walking the heap, you need to call Flush before
        /// attempting to walk the heap again.
        /// </summary>
        public override void FlushCachedData()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(ClrRuntime));
            }

            _domains      = null;
            _systemDomain = null;
            _sharedDomain = null;

            _helpers.DataReader.FlushCachedData();
            _helpers.FlushCachedData();

            DacLibrary.Flush();
        }
Example #11
0
        public NativeRuntime(ClrInfo info, DataTargetImpl dt, DacLibrary lib)
            : base(info, dt, lib)
        {
            byte[] tmp = new byte[sizeof(int)];

            if (!Request(DacRequests.VERSION, null, tmp))
            {
                throw new ClrDiagnosticsException("Failed to request dac version.", ClrDiagnosticsException.HR.DacError);
            }

            _dacRawVersion = BitConverter.ToInt32(tmp, 0);
            if (_dacRawVersion != 10 && _dacRawVersion != 11)
            {
                throw new ClrDiagnosticsException("Unsupported dac version.", ClrDiagnosticsException.HR.DacError);
            }
        }
Example #12
0
        public V45Runtime(ClrInfo info, DataTargetImpl dt, DacLibrary lib)
            : base(info, dt, lib)
        {
            if (!GetCommonMethodTables(ref _commonMTs))
                throw new ClrDiagnosticsException("Could not request common MethodTable list.", ClrDiagnosticsException.HR.DacError);

            // Ensure the version of the dac API matches the one we expect.  (Same for both
            // v2 and v4 rtm.)
            byte[] tmp = new byte[sizeof(int)];

            if (!Request(DacRequests.VERSION, null, tmp))
                throw new ClrDiagnosticsException("Failed to request dac version.", ClrDiagnosticsException.HR.DacError);

            int v = BitConverter.ToInt32(tmp, 0);
            if (v != 9)
                throw new ClrDiagnosticsException("Unsupported dac version.", ClrDiagnosticsException.HR.DacError);
        }
Example #13
0
        internal CallableCOMWrapper(DacLibrary library, ref Guid desiredInterface, IntPtr pUnknown)
        {
            Interlocked.Increment(ref _totalInstances);
            IUnknownVTable *tbl = *(IUnknownVTable **)pUnknown;

            var queryInterface = (QueryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(tbl->QueryInterface, typeof(QueryInterfaceDelegate));
            int hr             = queryInterface(pUnknown, ref desiredInterface, out IntPtr pCorrectUnknown);

            if (hr != 0)
            {
                GC.SuppressFinalize(this);
                throw new InvalidOperationException();
            }

            var release = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(tbl->Release, typeof(ReleaseDelegate));

            release(pUnknown);

            Self           = pCorrectUnknown;
            _unknownVTable = *(IUnknownVTable **)pCorrectUnknown;
            _library       = GCHandle.Alloc(library);
        }
Example #14
0
        static void Main(string[] args)
        {
            // needs to run in docker: AttachToProcess is not supported on Darwin 19.4.0
            int.TryParse(args[0], out var processId);
            Console.WriteLine("Attaching for PID: " + processId.ToString());
            var suspendOnStart = false;

            Console.WriteLine("Hello World!");
            DataTarget dataTarget = DataTarget.AttachToProcess(processId, suspendOnStart);

            if (dataTarget != null)
            {
                Console.WriteLine("Attached.");
                Console.WriteLine("Name: " + dataTarget.DataReader.DisplayName);
                Console.WriteLine("Arch: " + dataTarget.DataReader.Architecture.ToString());
                var modules = dataTarget.DataReader.EnumerateModules();
                foreach (var module in modules)
                {
                    Console.WriteLine("file: " + module.FileName);
                }

                var clrVersions = dataTarget.ClrVersions;

                foreach (var version in clrVersions)
                {
                    Console.WriteLine("dacPath: " + version.DacInfo.LocalDacPath);
                }


                // we have a live dac! (i think).
                var dac      = new DacLibrary(dataTarget, clrVersions[0].DacInfo.LocalDacPath);
                var dacDebug = dac.DacPrivateInterface.QueryInterface(Guid.NewGuid());
            }
            else
            {
                Console.WriteLine("Not attached.");
            }
        }
Example #15
0
 public ClrStackWalk(DacLibrary library, IntPtr pUnk)
     : base(library?.OwningLibrary, IID_IXCLRDataStackWalk, pUnk)
 {
 }
Example #16
0
 public ClrDataMethod(DacLibrary library, IntPtr pUnk)
     : base(library.OwningLibrary, ref IID_IXCLRDataMethodInstance, pUnk)
 {
 }
Example #17
0
 public SOSHandleEnum(DacLibrary library, IntPtr pUnk)
     : base(library?.OwningLibrary, IID_ISOSHandleEnum, pUnk)
 {
     ref readonly ISOSHandleEnumVTable vtable = ref Unsafe.AsRef <ISOSHandleEnumVTable>(_vtable);
Example #18
0
 public SOSNative(DacLibrary library, IntPtr pUnk) : base(library.OwningLibrary, ref IID_ISOSNative, pUnk)
 {
 }
Example #19
0
 public ClrDataProcess(DacLibrary library, IntPtr pUnknown)
     : base(library.OwningLibrary, ref IID_IXCLRDataProcess, pUnknown)
 {
     _library = library;
 }
Example #20
0
 public ClrmdRuntime(ClrInfo info, DacLibrary dac, IRuntimeHelpers helpers)
 {
     ClrInfo    = info;
     DacLibrary = dac;
     _helpers   = helpers ?? throw new ArgumentNullException(nameof(helpers));
 }
Example #21
0
 public SOSDac(DacLibrary lib, CallableCOMWrapper toClone) : base(toClone)
 {
     _library = lib;
 }
Example #22
0
 public ClrDataModule(DacLibrary library, IntPtr pUnknown)
     : base(library?.OwningLibrary, IID_IXCLRDataModule, pUnknown)
 {
 }
Example #23
0
 public ClrDataTask(DacLibrary library, IntPtr pUnk)
     : base(library.OwningLibrary, ref IID_IXCLRDataTask, pUnk)
 {
 }
Example #24
0
 public ClrDataProcess(DacLibrary library, CallableCOMWrapper toClone) : base(toClone)
 {
     _library = library;
 }
Example #25
0
 internal DesktopRuntimeBase(ClrInfo info, DataTargetImpl dt, DacLibrary lib)
     : base(info, dt, lib)
 {
 }
Example #26
0
 public MetadataImport(DacLibrary library, IntPtr pUnknown)
     : base(library?.OwningLibrary, IID_IMetaDataImport, pUnknown)
 {
 }
Example #27
0
 internal DesktopRuntimeBase(ClrInfo info, DataTargetImpl dt, DacLibrary lib)
     : base(info, dt, lib)
 {
 }
Example #28
0
 public SOSDac6(DacLibrary library, IntPtr ptr)
     : base(library?.OwningLibrary, IID_ISOSDac6, ptr)
 {
 }
Example #29
0
 public MetaDataImport(DacLibrary library, IntPtr pUnknown)
     : base(library, ref IID_IMetaDataImport, pUnknown)
 {
 }
Example #30
0
 public SOSDac(DacLibrary library, IntPtr ptr)
     : base(library.OwningLibrary, ref IID_ISOSDac, ptr)
 {
     _library = library;
 }
Example #31
0
 public SOSDac(DacLibrary?library, IntPtr ptr)
     : base(library?.OwningLibrary, IID_ISOSDac, ptr)
 {
     _library = library ?? throw new ArgumentNullException(nameof(library));
 }
Example #32
0
 internal DesktopRuntimeBase(DataTargetImpl dt, DacLibrary lib)
     : base(dt, lib)
 {
 }