示例#1
0
        /// <summary>
        /// Compares the memory context to each context in the given array in the manner indicated by compare flags,
        /// returning an index of the first context that matches. (http://msdn.microsoft.com/en-ca/library/bb161750.aspx)
        /// </summary>
        /// <param name="uContextCompare"> A value from the CONTEXT_COMPARE enumeration that determines the type of comparison. </param>
        /// <param name="compareToItems"> An array of references to the IDebugMemoryContext2 objects to compare against. </param>
        /// <param name="compareToLength"> The number of contexts in the compareToItems array. </param>
        /// <param name="foundIndex"> Returns the index of the first memory context that satisfies the comparison. </param>
        /// <returns> If successful, returns S_OK; otherwise, returns an error code. </returns>
        public int Compare(enum_CONTEXT_COMPARE uContextCompare, IDebugMemoryContext2[] compareToItems, uint compareToLength, out uint foundIndex)
        {
            foundIndex = uint.MaxValue;

            try
            {
                enum_CONTEXT_COMPARE contextCompare = (enum_CONTEXT_COMPARE)uContextCompare;

                for (uint c = 0; c < compareToLength; c++)
                {
                    AD7MemoryAddress compareTo = compareToItems[c] as AD7MemoryAddress;
                    if (compareTo == null)
                    {
                        continue;
                    }

                    if (!AD7Engine.ReferenceEquals(this.m_engine, compareTo.m_engine))
                    {
                        continue;
                    }

                    bool result;

                    switch (contextCompare)
                    {
                    case enum_CONTEXT_COMPARE.CONTEXT_EQUAL:
                        result = (this.m_address == compareTo.m_address);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_LESS_THAN:
                        result = (this.m_address < compareTo.m_address);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_GREATER_THAN:
                        result = (this.m_address > compareTo.m_address);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_LESS_THAN_OR_EQUAL:
                        result = (this.m_address <= compareTo.m_address);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_GREATER_THAN_OR_EQUAL:
                        result = (this.m_address >= compareTo.m_address);
                        break;

                    // The VSNDK debug engine doesn't understand scopes or functions
                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_SCOPE:
                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_FUNCTION:
                        result = (this.m_address == compareTo.m_address);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_MODULE:
                        result = (this.m_address == compareTo.m_address);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_PROCESS:
                        result = true;
                        break;

                    default:
                        // A new comparison was invented that we don't support
                        return(VSConstants.E_NOTIMPL);
                    }

                    if (result)
                    {
                        foundIndex = c;
                        return(VSConstants.S_OK);
                    }
                }

                return(VSConstants.S_FALSE);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
示例#2
0
        // Compares the memory context to each context in the given array in the manner indicated by compare flags,
        // returning an index of the first context that matches.
        public int Compare(enum_CONTEXT_COMPARE uContextCompare, IDebugMemoryContext2[] compareToItems, uint compareToLength, out uint foundIndex)
        {
            foundIndex = uint.MaxValue;

            enum_CONTEXT_COMPARE contextCompare = (enum_CONTEXT_COMPARE)uContextCompare;

            for (uint c = 0; c < compareToLength; c++)
            {
                AD7MemoryAddress compareTo = compareToItems[c] as AD7MemoryAddress;
                if (compareTo == null)
                {
                    continue;
                }

                if (!AD7Engine.ReferenceEquals(this._engine, compareTo._engine))
                {
                    continue;
                }

                bool result;

                switch (contextCompare)
                {
                case enum_CONTEXT_COMPARE.CONTEXT_EQUAL:
                    result = (this._lineNo == compareTo._lineNo);
                    break;

                case enum_CONTEXT_COMPARE.CONTEXT_LESS_THAN:
                    result = (this._lineNo < compareTo._lineNo);
                    break;

                case enum_CONTEXT_COMPARE.CONTEXT_GREATER_THAN:
                    result = (this._lineNo > compareTo._lineNo);
                    break;

                case enum_CONTEXT_COMPARE.CONTEXT_LESS_THAN_OR_EQUAL:
                    result = (this._lineNo <= compareTo._lineNo);
                    break;

                case enum_CONTEXT_COMPARE.CONTEXT_GREATER_THAN_OR_EQUAL:
                    result = (this._lineNo >= compareTo._lineNo);
                    break;

                case enum_CONTEXT_COMPARE.CONTEXT_SAME_SCOPE:
                case enum_CONTEXT_COMPARE.CONTEXT_SAME_FUNCTION:
                    if (_frame != null)
                    {
                        result = compareTo._filename == _filename && (compareTo._lineNo + 1) >= _frame.StartLine && (compareTo._lineNo + 1) <= _frame.EndLine;
                    }
                    else if (compareTo._frame != null)
                    {
                        result = compareTo._filename == _filename && (_lineNo + 1) >= compareTo._frame.StartLine && (compareTo._lineNo + 1) <= compareTo._frame.EndLine;
                    }
                    else
                    {
                        result = this._lineNo == compareTo._lineNo && this._filename == compareTo._filename;
                    }
                    break;

                case enum_CONTEXT_COMPARE.CONTEXT_SAME_MODULE:
                    result = _filename == compareTo._filename;
                    break;

                case enum_CONTEXT_COMPARE.CONTEXT_SAME_PROCESS:
                    result = true;
                    break;

                default:
                    // A new comparison was invented that we don't support
                    return(VSConstants.E_NOTIMPL);
                }

                if (result)
                {
                    foundIndex = c;
                    return(VSConstants.S_OK);
                }
            }

            return(VSConstants.S_FALSE);
        }