예제 #1
0
        public DacLibrary(DataTargetImpl dataTarget, string dacDll)
        {
            if (dataTarget.ClrVersions.Count == 0)
            {
                throw new ClrDiagnosticsException(String.Format("Process is not a CLR process!"));
            }

            _library = NativeMethods.LoadLibrary(dacDll);
            if (_library == IntPtr.Zero)
            {
                throw new ClrDiagnosticsException("Failed to load dac: " + dacDll);
            }

            IntPtr addr = NativeMethods.GetProcAddress(_library, "CLRDataCreateInstance");

            _dacDataTarget = new DacDataTarget(dataTarget);

            object obj;

            NativeMethods.CreateDacInstance func = (NativeMethods.CreateDacInstance)Marshal.GetDelegateForFunctionPointer(addr, typeof(NativeMethods.CreateDacInstance));
            Guid guid = new Guid("5c552ab6-fc09-4cb3-8e36-22fa03c798b7");
            int  res  = func(ref guid, _dacDataTarget, out obj);

            if (res == 0)
            {
                _dac = obj as IXCLRDataProcess;
            }

            if (_dac == null)
            {
                throw new ClrDiagnosticsException("Failure loading DAC: CreateDacInstance failed 0x" + res.ToString("x"), ClrDiagnosticsException.HR.DacError);
            }
        }
예제 #2
0
 public DacDataTarget(DataTargetImpl dataTarget)
 {
     _dataTarget = dataTarget;
     _dataReader = _dataTarget.DataReader;
     _modules    = dataTarget.EnumerateModules().ToArray();
     Array.Sort(_modules, delegate(ModuleInfo a, ModuleInfo b) { return(a.ImageBase.CompareTo(b.ImageBase)); });
 }
예제 #3
0
        /// <summary>
        /// Creates a data target from an existing IDebugClient interface.  If you created and attached
        /// a dbgeng based debugger to a process you may pass the IDebugClient RCW object to this function
        /// to create the DataTarget.
        /// </summary>
        /// <param name="client">The dbgeng IDebugClient object.  We will query interface on this for IDebugClient.</param>
        /// <returns>A DataTarget instance.</returns>
        public static DataTarget CreateFromDebuggerInterface(IDebugClient client)
        {
            DbgEngDataReader reader     = new DbgEngDataReader(client);
            DataTargetImpl   dataTarget = new DataTargetImpl(reader, reader.DebuggerInterface);

            return(dataTarget);
        }
예제 #4
0
        public RuntimeBase(ClrInfo info, DataTargetImpl dataTarget, DacLibrary lib)
        {
            Debug.Assert(lib != null);
            Debug.Assert(lib.DacInterface != null);

            ClrInfo       = info;
            _dataTarget   = dataTarget;
            _library      = lib;
            _dacInterface = _library.DacInterface;
            InitApi();

            _dacInterface.Flush();

            IGCInfo data = GetGCInfo();

            if (data == null)
            {
                throw new ClrDiagnosticsException("This runtime is not initialized and contains no data.", ClrDiagnosticsException.HR.RuntimeUninitialized);
            }

            ServerGC    = data.ServerMode;
            HeapCount   = data.HeapCount;
            CanWalkHeap = data.GCStructuresValid && !dataTarget.DataReader.IsMinidump;
            _dataReader = dataTarget.DataReader;
        }
예제 #5
0
        /// <summary>
        /// Attaches to a snapshot process (see https://msdn.microsoft.com/en-us/library/dn457825(v=vs.85).aspx).
        /// </summary>
        /// <param name="pid">The process ID of the process to attach to.</param>
        /// <returns>A DataTarget instance.</returns>
        public static DataTarget CreateSnapshotAndAttach(int pid)
        {
            IDataReader    reader     = new LiveDataReader(pid, true);
            DataTargetImpl dataTarget = new DataTargetImpl(reader, null);

            return(dataTarget);
        }
예제 #6
0
 public DacLibrary(DataTargetImpl dataTarget, object ix)
 {
     _dac = ix as IXCLRDataProcess;
     if (_dac == null)
     {
         throw new ArgumentException("clrDataProcess not an instance of IXCLRDataProcess");
     }
 }
        internal ClrInfo(DataTargetImpl dt, ClrFlavor flavor, ModuleInfo module, DacInfo dacInfo, string dacLocation)
        {
            Debug.Assert(dacInfo != null);

            Flavor           = flavor;
            DacInfo          = dacInfo;
            ModuleInfo       = module;
            module.IsRuntime = true;
            _dataTarget      = dt;
            _dacLocation     = dacLocation;
        }
예제 #8
0
        /// <summary>
        /// Attaches to a live process.
        /// </summary>
        /// <param name="pid">The process ID of the process to attach to.</param>
        /// <param name="msecTimeout">Timeout in milliseconds.</param>
        /// <param name="attachFlag">The type of attach requested for the target process.</param>
        /// <returns>A DataTarget instance.</returns>
        public static DataTarget AttachToProcess(int pid, uint msecTimeout, AttachFlag attachFlag)
        {
            IDebugClient client = null;
            IDataReader  reader;

            if (attachFlag == AttachFlag.Passive)
            {
#if NET45
                reader = new LiveDataReader(pid, false);
#else
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    reader = new LiveDataReader(pid, false);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    reader = new Linux.LinuxLiveDataReader((uint)pid);
                }
                else
                {
                    throw new NotSupportedException("Passive attach is not supported on OSX.s");
                }
#endif
            }
            else
            {
#if !NET45
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    throw new PlatformNotSupportedException("Currently only AttachFlag.Passive is supported for AttachToProcess");
                }
#endif

                DbgEngDataReader dbgeng = new DbgEngDataReader(pid, attachFlag, msecTimeout);
                reader = dbgeng;
                client = dbgeng.DebuggerInterface;
            }

            DataTargetImpl dataTarget = new DataTargetImpl(reader, client);
#if !NET45
            if (reader is Linux.LinuxLiveDataReader)
            {
                // TODO: discuss this design of
                // 1) add a method to IDataReader2 to return the list of module full path
                // 2) make DefaultSymbolLocator use that list as hint to load binaries
                dataTarget.SymbolLocator = new Linux.LinuxDefaultSymbolLocator(((Linux.LinuxLiveDataReader)reader).GetModulesFullPath());
            }
#endif
            return(dataTarget);
        }
예제 #9
0
        /// <summary>
        /// Attaches to a live process.
        /// </summary>
        /// <param name="pid">The process ID of the process to attach to.</param>
        /// <param name="msecTimeout">Timeout in milliseconds.</param>
        /// <param name="attachFlag">The type of attach requested for the target process.</param>
        /// <returns>A DataTarget instance.</returns>
        public static DataTarget AttachToProcess(int pid, uint msecTimeout, AttachFlag attachFlag)
        {
            IDebugClient client = null;
            IDataReader  reader;

            if (attachFlag == AttachFlag.Passive)
            {
                reader = new LiveDataReader(pid, false);
            }
            else
            {
                DbgEngDataReader dbgeng = new DbgEngDataReader(pid, attachFlag, msecTimeout);
                reader = dbgeng;
                client = dbgeng.DebuggerInterface;
            }

            DataTargetImpl dataTarget = new DataTargetImpl(reader, client);

            return(dataTarget);
        }
예제 #10
0
        public LegacyRuntime(DataTargetImpl dt, DacLibrary lib, DesktopVersion version, int minor)
            : base(dt, lib)
        {
            _version = version;
            _minor = minor;

            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 != 8)
                throw new ClrDiagnosticsException("Unsupported dac version.", ClrDiagnosticsException.HR.DacError);
        }
예제 #11
0
        public RuntimeBase(ClrInfo info, DataTargetImpl dataTarget, DacLibrary lib)
        {
            Debug.Assert(lib != null);
            Debug.Assert(lib.DacInterface != null);

            ClrInfo       = info;
            _dataTarget   = dataTarget;
            _library      = lib;
            _dacInterface = _library.DacInterface;
            InitApi();

            _dacInterface.Flush();

            IGCInfo data = GetGCInfo();

            if (data != null)
            {
                ServerGC    = data.ServerMode;
                HeapCount   = data.HeapCount;
                CanWalkHeap = data.GCStructuresValid;
            }
            _dataReader = dataTarget.DataReader;
        }
예제 #12
0
        internal ClrInfo(DataTargetImpl dt, ClrFlavor flavor, ModuleInfo module, DacInfo dacInfo, string dacLocation)
        {
            Debug.Assert(dacInfo != null);

            Flavor = flavor;
            DacInfo = dacInfo;
            ModuleInfo = module;
            module.IsRuntime = true;
            _dataTarget = dt;
            _dacLocation = dacLocation;
        }
예제 #13
0
 public DacDataTarget(DataTargetImpl dataTarget)
 {
     _dataTarget = dataTarget;
     _dataReader = _dataTarget.DataReader;
     _modules = dataTarget.EnumerateModules().ToArray();
     Array.Sort(_modules, delegate (ModuleInfo a, ModuleInfo b) { return a.ImageBase.CompareTo(b.ImageBase); });
 }
예제 #14
0
        public DacLibrary(DataTargetImpl dataTarget, string dacDll)
        {
            if (dataTarget.ClrVersions.Count == 0)
                throw new ClrDiagnosticsException(String.Format("Process is not a CLR process!"));

            _library = NativeMethods.LoadLibrary(dacDll);
            if (_library == IntPtr.Zero)
                throw new ClrDiagnosticsException("Failed to load dac: " + dacDll);

            IntPtr addr = NativeMethods.GetProcAddress(_library, "CLRDataCreateInstance");
            _dacDataTarget = new DacDataTarget(dataTarget);

            object obj;
            NativeMethods.CreateDacInstance func = (NativeMethods.CreateDacInstance)Marshal.GetDelegateForFunctionPointer(addr, typeof(NativeMethods.CreateDacInstance));
            Guid guid = new Guid("5c552ab6-fc09-4cb3-8e36-22fa03c798b7");
            int res = func(ref guid, _dacDataTarget, out obj);

            if (res == 0)
                _dac = obj as IXCLRDataProcess;

            if (_dac == null)
                throw new ClrDiagnosticsException("Failure loading DAC: CreateDacInstance failed 0x" + res.ToString("x"), ClrDiagnosticsException.HR.DacError);
        }
예제 #15
0
 public DacLibrary(DataTargetImpl dataTarget, object ix)
 {
     _dac = ix as IXCLRDataProcess;
     if (_dac == null)
         throw new ArgumentException("clrDataProcess not an instance of IXCLRDataProcess");
 }
예제 #16
0
        /// <summary>
        /// Creates a data target from an existing IDebugClient interface.  If you created and attached
        /// a dbgeng based debugger to a process you may pass the IDebugClient RCW object to this function
        /// to create the DataTarget.
        /// </summary>
        /// <param name="client">The dbgeng IDebugClient object.  We will query interface on this for IDebugClient.</param>
        /// <returns>A DataTarget instance.</returns>
        public static DataTarget CreateFromDebuggerInterface(Microsoft.Diagnostics.Runtime.Interop.IDebugClient client)
        {
            DbgEngDataReader reader = new DbgEngDataReader(client);
            DataTargetImpl dataTarget = new DataTargetImpl(reader, reader.DebuggerInterface);

            return dataTarget;
        }
예제 #17
0
        /// <summary>
        /// Attaches to a live process.
        /// </summary>
        /// <param name="pid">The process ID of the process to attach to.</param>
        /// <param name="msecTimeout">Timeout in milliseconds.</param>
        /// <param name="attachFlag">The type of attach requested for the target process.</param>
        /// <returns>A DataTarget instance.</returns>
        public static DataTarget AttachToProcess(int pid, uint msecTimeout, AttachFlag attachFlag)
        {
            Microsoft.Diagnostics.Runtime.Interop.IDebugClient client = null;
            IDataReader reader;
            if (attachFlag == AttachFlag.Passive)
            {
                reader = new LiveDataReader(pid);
            }
            else
            {
                var dbgeng = new DbgEngDataReader(pid, attachFlag, msecTimeout);
                reader = dbgeng;
                client = dbgeng.DebuggerInterface;
            }

            DataTargetImpl dataTarget = new DataTargetImpl(reader, client);
            return dataTarget;
        }
예제 #18
0
 public DacDataTarget(DataTargetImpl dataTarget)
 {
     m_dataTarget = dataTarget;
     m_dataReader = m_dataTarget.DataReader;
 }
예제 #19
0
파일: DacLibrary.cs 프로젝트: anurse/clrmd
 internal DacLibrary(DataTargetImpl dataTarget, IntPtr pUnk)
 {
     InternalDacPrivateInterface = new ClrDataProcess(this, pUnk);
 }
예제 #20
0
 public DacDataTarget(DataTargetImpl dataTarget)
 {
     m_dataTarget = dataTarget;
     m_dataReader = m_dataTarget.DataReader;
 }