Пример #1
0
        /// <summary>
        /// Internal stack frame initialization based on IP address.
        /// </summary>
        private void InitializeForIpAddress(IntPtr ipAddress, bool needFileInfo)
        {
            _ipAddress    = ipAddress;
            _needFileInfo = needFileInfo;

            if (_ipAddress == StackTraceHelper.SpecialIP.EdiSeparator)
            {
                SetIsLastFrameFromForeignExceptionStackTrace(true);
            }
            else if (_ipAddress != IntPtr.Zero)
            {
                IntPtr methodStartAddress = RuntimeImports.RhFindMethodStartAddress(ipAddress);

                _nativeOffset = (int)(_ipAddress.ToInt64() - methodStartAddress.ToInt64());

                DeveloperExperience.Default.TryGetILOffsetWithinMethod(_ipAddress, out _ilOffset);
                DeveloperExperience.Default.TryGetMethodBase(methodStartAddress, out _method);

                if (needFileInfo)
                {
                    DeveloperExperience.Default.TryGetSourceLineInfo(
                        _ipAddress,
                        out _fileName,
                        out _lineNumber,
                        out _columnNumber);
                }
            }
        }
Пример #2
0
        public static string TryGetMethodDisplayStringFromIp(IntPtr ip)
        {
            StackTraceMetadataCallbacks callbacks = StackTraceCallbacksIfAvailable;

            if (callbacks == null)
            {
                return(null);
            }

            ip = RuntimeImports.RhFindMethodStartAddress(ip);
            if (ip == IntPtr.Zero)
            {
                return(null);
            }

            return(callbacks.TryGetMethodNameFromStartAddress(ip));
        }
Пример #3
0
        public virtual String CreateStackTraceString(IntPtr ip, bool includeFileInfo)
        {
            ReflectionExecutionDomainCallbacks reflectionCallbacks = RuntimeAugments.CallbacksIfAvailable;
            String moduleFullFileName = null;

            if (reflectionCallbacks != null)
            {
                IntPtr methodStart = RuntimeImports.RhFindMethodStartAddress(ip);
                if (methodStart != IntPtr.Zero)
                {
                    string methodName = string.Empty;
                    try
                    {
                        methodName = reflectionCallbacks.GetMethodNameFromStartAddressIfAvailable(methodStart);
                    }
                    catch { }

                    if (!string.IsNullOrEmpty(methodName))
                    {
                        return(methodName);
                    }
                }

                // If we don't have precise information, try to map it at least back to the right module.
                IntPtr moduleBase = RuntimeImports.RhGetModuleFromPointer(ip);
                moduleFullFileName = RuntimeAugments.TryGetFullPathToApplicationModule(moduleBase);
            }

            // Without any callbacks or the ability to map ip correctly we better admit that we don't know
            if (string.IsNullOrEmpty(moduleFullFileName))
            {
                return("<unknown>");
            }

            StringBuilder sb = new StringBuilder();
            String        fileNameWithoutExtension = GetFileNameWithoutExtension(moduleFullFileName);
            int           rva = RuntimeAugments.ConvertIpToRva(ip);

            sb.Append(fileNameWithoutExtension);
            sb.Append("!<BaseAddress>+0x");
            sb.Append(rva.ToString("x"));
            return(sb.ToString());
        }
Пример #4
0
        public virtual string CreateStackTraceString(IntPtr ip, bool includeFileInfo)
        {
            if (!IsMetadataStackTraceResolutionDisabled())
            {
                StackTraceMetadataCallbacks stackTraceCallbacks = RuntimeAugments.StackTraceCallbacksIfAvailable;
                if (stackTraceCallbacks != null)
                {
                    IntPtr methodStart = RuntimeImports.RhFindMethodStartAddress(ip);
                    if (methodStart != IntPtr.Zero)
                    {
                        string methodName = stackTraceCallbacks.TryGetMethodNameFromStartAddress(methodStart);
                        if (methodName != null)
                        {
                            if (ip != methodStart)
                            {
                                methodName += " + 0x" + (ip.ToInt64() - methodStart.ToInt64()).ToString("x");
                            }
                            return(methodName);
                        }
                    }
                }
            }

            // If we don't have precise information, try to map it at least back to the right module.
            IntPtr moduleBase         = RuntimeImports.RhGetOSModuleFromPointer(ip);
            string moduleFullFileName = RuntimeAugments.TryGetFullPathToApplicationModule(moduleBase);

            // Without any callbacks or the ability to map ip correctly we better admit that we don't know
            if (string.IsNullOrEmpty(moduleFullFileName))
            {
                return("<unknown>");
            }

            StringBuilder sb = new StringBuilder();
            string        fileNameWithoutExtension = GetFileNameWithoutExtension(moduleFullFileName);
            int           rva = RuntimeAugments.ConvertIpToRva(ip);

            sb.Append(fileNameWithoutExtension);
            sb.Append("!<BaseAddress>+0x");
            sb.Append(rva.ToString("x"));
            return(sb.ToString());
        }
Пример #5
0
        public virtual String CreateStackTraceString(IntPtr ip, bool includeFileInfo)
        {
            ReflectionExecutionDomainCallbacks reflectionCallbacks = RuntimeAugments.CallbacksIfAvailable;

            if (reflectionCallbacks != null)
            {
                IntPtr methodStart = RuntimeImports.RhFindMethodStartAddress(ip);
                if (methodStart != IntPtr.Zero)
                {
                    string methodName = string.Empty;
                    try
                    {
                        methodName = reflectionCallbacks.GetMethodNameFromStartAddressIfAvailable(methodStart);
                    }
                    catch { }

                    if (!string.IsNullOrEmpty(methodName))
                    {
                        return(methodName);
                    }
                }
            }

            String fullPathToApplication = RuntimeAugments.TryGetFullPathToMainApplication();

            if (string.IsNullOrEmpty(fullPathToApplication))
            {
                return("<unknown>");
            }

            StringBuilder sb = new StringBuilder();
            String        fileNameWithoutExtension = GetFileNameWithoutExtension(fullPathToApplication);
            int           rva = RuntimeAugments.ConvertIpToRva(ip);

            sb.Append(fileNameWithoutExtension);
            sb.Append("!<BaseAddress>+0x");
            sb.Append(rva.ToString("x"));
            return(sb.ToString());
        }