// Gets the breakpoint resolution information that describes this breakpoint.
        int IDebugBreakpointResolution2.GetResolutionInfo(enum_BPRESI_FIELDS dwFields, BP_RESOLUTION_INFO[] pBPResolutionInfo)
        {
            if ((dwFields & enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION) != 0)
            {
                // The sample engine only supports code breakpoints.
                BP_RESOLUTION_LOCATION location = new BP_RESOLUTION_LOCATION();
                location.bpType = (uint)enum_BP_TYPE.BPT_CODE;

                // The debugger will not QI the IDebugCodeContex2 interface returned here. We must pass the pointer
                // to IDebugCodeContex2 and not IUnknown.
                AD7MemoryAddress codeContext = new AD7MemoryAddress(_engine, Addr, _functionName);
                codeContext.SetDocumentContext(_documentContext);
                location.unionmember1 = Marshal.GetComInterfaceForObject(codeContext, typeof(IDebugCodeContext2));
                pBPResolutionInfo[0].bpResLocation = location;
                pBPResolutionInfo[0].dwFields |= enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION;
            }

            if ((dwFields & enum_BPRESI_FIELDS.BPRESI_PROGRAM) != 0)
            {
                pBPResolutionInfo[0].pProgram = (IDebugProgram2)_engine;
                pBPResolutionInfo[0].dwFields |= enum_BPRESI_FIELDS.BPRESI_PROGRAM;
            }

            return Constants.S_OK;
        }
Esempio n. 2
0
        public AD7StackFrame(AD7Engine engine, AD7Thread thread, ThreadContext threadContext)
        {
            Debug.Assert(threadContext != null, "ThreadContext is null");

            Engine = engine;
            Thread = thread;
            ThreadContext = threadContext;

            _textPosition = threadContext.TextPosition;
            _functionName = threadContext.Function;

            if (threadContext.pc.HasValue)
            {
                _codeCxt = new AD7MemoryAddress(this.Engine, threadContext.pc.Value, _functionName);
            }

            if (_textPosition != null)
            {
                _documentCxt = new AD7DocumentContext(_textPosition, _codeCxt);

                if (_codeCxt != null)
                {
                    _codeCxt.SetDocumentContext(_documentCxt);
                }
            }
        }
Esempio n. 3
0
        // Retrieves a list of all code contexts associated with this document context.
        // The engine sample only supports one code context per document context and 
        // the code contexts are always memory addresses.
        int IDebugDocumentContext2.EnumCodeContexts(out IEnumDebugCodeContexts2 ppEnumCodeCxts)
        {
            ppEnumCodeCxts = null;

            if (_codeContext == null)
            {
                return Constants.E_FAIL;
            }

            try
            {
                AD7MemoryAddress[] codeContexts = new AD7MemoryAddress[1];
                codeContexts[0] = _codeContext;
                ppEnumCodeCxts = new AD7CodeContextEnum(codeContexts);
                return Constants.S_OK;
            }
            catch (MIException e)
            {
                return e.HResult;
            }
            catch (Exception e)
            {
                return EngineUtils.UnexpectedException(e);
            }
        }
        // Gets the breakpoint resolution information that describes this breakpoint.
        int IDebugBreakpointResolution2.GetResolutionInfo(enum_BPRESI_FIELDS dwFields, BP_RESOLUTION_INFO[] pBPResolutionInfo)
        {
            if ((dwFields & enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION) != 0)
            {
                BP_RESOLUTION_LOCATION location = new BP_RESOLUTION_LOCATION();
                location.bpType = (uint)_breakType;
                if (_breakType == enum_BP_TYPE.BPT_CODE)
                {
                    // The debugger will not QI the IDebugCodeContex2 interface returned here. We must pass the pointer
                    // to IDebugCodeContex2 and not IUnknown.
                    AD7MemoryAddress codeContext = new AD7MemoryAddress(_engine, Addr, _functionName);
                    codeContext.SetDocumentContext(_documentContext);
                    location.unionmember1 = HostMarshal.RegisterCodeContext(codeContext);
                    pBPResolutionInfo[0].bpResLocation = location;
                    pBPResolutionInfo[0].dwFields |= enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION;
                }
                else if (_breakType == enum_BP_TYPE.BPT_DATA)
                {
                    location.unionmember1 = HostMarshal.GetIntPtrForDataBreakpointAddress(EngineUtils.AsAddr(Addr, _engine.DebuggedProcess.Is64BitArch));
                    pBPResolutionInfo[0].bpResLocation = location;
                    pBPResolutionInfo[0].dwFields |= enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION;
                }
            }

            if ((dwFields & enum_BPRESI_FIELDS.BPRESI_PROGRAM) != 0)
            {
                pBPResolutionInfo[0].pProgram = (IDebugProgram2)_engine;
                pBPResolutionInfo[0].dwFields |= enum_BPRESI_FIELDS.BPRESI_PROGRAM;
            }

            return Constants.S_OK;
        }
Esempio n. 5
0
 public AD7DocumentContext(MITextPosition textPosition, AD7MemoryAddress codeContext)
 {
     _textPosition = textPosition;
     _codeContext = codeContext;
 }
Esempio n. 6
0
 public int GetCodeContext(ulong uCodeLocationId, out IDebugCodeContext2 ppCodeContext)
 {
     ppCodeContext = new AD7MemoryAddress(_engine, (uint)uCodeLocationId, null);
     return Constants.S_OK;
 }
Esempio n. 7
0
        // Get the document context for this pending breakpoint. A document context is a abstract representation of a source file 
        // location.
        public AD7DocumentContext GetDocumentContext(ulong address, string functionName)
        {
            IDebugDocumentPosition2 docPosition = HostMarshal.GetDocumentPositionForIntPtr(_bpRequestInfo.bpLocation.unionmember2);
            string documentName;
            EngineUtils.CheckOk(docPosition.GetFileName(out documentName));

            // Get the location in the document that the breakpoint is in.
            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

            AD7MemoryAddress codeContext = new AD7MemoryAddress(_engine, address, functionName);

            return new AD7DocumentContext(new MITextPosition(documentName, startPosition[0], startPosition[0]), codeContext);
        }
Esempio n. 8
0
 public AD7DocumentContext(MITextPosition textPosition, AD7MemoryAddress codeContext, DebuggedProcess debuggedProcess)
 {
     _textPosition    = textPosition;
     _codeContext     = codeContext;
     _debuggedProcess = debuggedProcess;
 }
        // Get the document context for this pending breakpoint. A document context is a abstract representation of a source file 
        // location.
        public AD7DocumentContext GetDocumentContext(ulong address, string functionName)
        {
            if ((enum_BP_LOCATION_TYPE)_bpRequestInfo.bpLocation.bpLocationType == enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE)
            {
                IDebugDocumentPosition2 docPosition = HostMarshal.GetDocumentPositionForIntPtr(_bpRequestInfo.bpLocation.unionmember2);
                string documentName;
                EngineUtils.CheckOk(docPosition.GetFileName(out documentName));

                // Get the location in the document that the breakpoint is in.
                TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
                TEXT_POSITION[] endPosition = new TEXT_POSITION[1];
                EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

                AD7MemoryAddress codeContext = new AD7MemoryAddress(_engine, address, functionName);

                return new AD7DocumentContext(new MITextPosition(documentName, startPosition[0], startPosition[0]), codeContext, _engine.DebuggedProcess);
            }
            else
            {
                return null;
            }
        }
Esempio n. 10
0
 // Subtracts a specified value from the current context's address to create a new context.
 public int Subtract(ulong dwCount, out IDebugMemoryContext2 ppMemCxt)
 {
     ppMemCxt = new AD7MemoryAddress(_engine, _address - (uint)dwCount, null);
     return Constants.S_OK;
 }
Esempio n. 11
0
 public int GetCodeContext(ulong uCodeLocationId, out IDebugCodeContext2 ppCodeContext)
 {
     ppCodeContext = new AD7MemoryAddress(_engine, uCodeLocationId, null);
     return(Constants.S_OK);
 }
Esempio n. 12
0
 int IDebugMemoryBytesDAP.CreateMemoryContext(ulong address, out IDebugMemoryContext2 ppResult)
 {
     ppResult = new AD7MemoryAddress(this, address, null);
     return(Constants.S_OK);
 }
Esempio n. 13
0
 public AD7DocumentContext(MITextPosition textPosition, AD7MemoryAddress codeContext, DebuggedProcess debuggedProcess)
 {
     _textPosition = textPosition;
     _codeContext = codeContext;
     _debuggedProcess = debuggedProcess;
 }
Esempio n. 14
0
 public AD7DocumentContext(MITextPosition textPosition, AD7MemoryAddress codeContext)
 {
     _textPosition = textPosition;
     _codeContext  = codeContext;
 }
Esempio n. 15
0
 // Adds a specified value to the current context's address to create a new context.
 public int Add(ulong dwCount, out IDebugMemoryContext2 newAddress)
 {
     newAddress = new AD7MemoryAddress(_engine, (uint)dwCount + _address, null);
     return(Constants.S_OK);
 }
Esempio n. 16
0
 // Returns the memory context for a property value.
 public int GetMemoryContext(out IDebugMemoryContext2 ppMemory)
 {
     ppMemory = null;
     if (_variableInformation.Error)
         return AD7_HRESULT.S_GETMEMORYCONTEXT_NO_MEMORY_CONTEXT;
     // try to interpret the result as an address
     string v = _variableInformation.Value;
     v = v.Trim();
     if (v.Length == 0)
     {
         return AD7_HRESULT.S_GETMEMORYCONTEXT_NO_MEMORY_CONTEXT;
     }
     if (v[0] == '{')
     {
         // strip type name and trailing spaces
         v = v.Substring(v.IndexOf('}') + 1);
         v = v.Trim();
     }
     int i = v.IndexOf(' ');
     if (i > 0)
     {
         v = v.Substring(0, i);
     }
     uint addr;
     if (!UInt32.TryParse(v, System.Globalization.NumberStyles.Any, null, out addr))
     {
         if (v.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
         {
             v = v.Substring(2);
             if (!UInt32.TryParse(v, System.Globalization.NumberStyles.AllowHexSpecifier, null, out addr))
             {
                 return AD7_HRESULT.S_GETMEMORYCONTEXT_NO_MEMORY_CONTEXT;
             }
         }
         else
         {
             return AD7_HRESULT.S_GETMEMORYCONTEXT_NO_MEMORY_CONTEXT;
         }
     }
     ppMemory = new AD7MemoryAddress(DebuggedProcess.g_Process.Engine, addr, null);
     return Constants.S_OK;
 }
Esempio n. 17
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 contextCompare, IDebugMemoryContext2[] compareToItems, uint compareToLength, out uint foundIndex)
        {
            foundIndex = uint.MaxValue;

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

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

                    bool result;

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

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

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

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

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

                    // The debug engine doesn't understand scopes
                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_SCOPE:
                        result = (_address == compareTo._address);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_FUNCTION:
                        if (_address == compareTo._address)
                        {
                            result = true;
                            break;
                        }
                        string funcThis = Engine.GetAddressDescription(_address);
                        if (string.IsNullOrEmpty(funcThis))
                        {
                            result = false;
                            break;
                        }
                        string funcCompareTo = Engine.GetAddressDescription(compareTo._address);
                        result = (funcThis == funcCompareTo);
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_MODULE:
                        result = (_address == compareTo._address);
                        if (result == false)
                        {
                            DebuggedModule module = _engine.DebuggedProcess.ResolveAddress(_address);

                            if (module != null)
                            {
                                result = module.AddressInModule(compareTo._address);
                            }
                        }
                        break;

                    case enum_CONTEXT_COMPARE.CONTEXT_SAME_PROCESS:
                        result = true;
                        break;

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

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

                return(Constants.S_FALSE);
            }
            catch (MIException e)
            {
                return(e.HResult);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
Esempio n. 18
0
 // Adds a specified value to the current context's address to create a new context.
 public int Add(ulong dwCount, out IDebugMemoryContext2 newAddress)
 {
     newAddress = new AD7MemoryAddress(_engine, (uint)dwCount + _address, null);
     return Constants.S_OK;
 }
Esempio n. 19
0
 // Subtracts a specified value from the current context's address to create a new context.
 public int Subtract(ulong dwCount, out IDebugMemoryContext2 ppMemCxt)
 {
     ppMemCxt = new AD7MemoryAddress(_engine, _address - (uint)dwCount, null);
     return(Constants.S_OK);
 }
Esempio n. 20
0
        // Enumerates the code contexts for a given position in a source file.
        public int EnumCodeContexts(IDebugDocumentPosition2 docPosition, out IEnumDebugCodeContexts2 ppEnum)
        {
            string documentName;
            EngineUtils.CheckOk(docPosition.GetFileName(out documentName));

            // Get the location in the document
            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));
            List<IDebugCodeContext2> codeContexts = new List<IDebugCodeContext2>();

            List<ulong> addresses = null;
            uint line = startPosition[0].dwLine + 1;
            _debuggedProcess.WorkerThread.RunOperation(async () =>
            {
                addresses = await DebuggedProcess.StartAddressesForLine(documentName, line);
            });

            if (addresses != null && addresses.Count > 0)
            {
                foreach (var a in addresses)
                {
                    var codeCxt = new AD7MemoryAddress(this, a, null);
                    TEXT_POSITION pos;
                    pos.dwLine = line;
                    pos.dwColumn = 0;
                    MITextPosition textPosition = new MITextPosition(documentName, pos, pos);
                    codeCxt.SetDocumentContext(new AD7DocumentContext(textPosition, codeCxt, this.DebuggedProcess));
                    codeContexts.Add(codeCxt);
                }
                if (codeContexts.Count > 0)
                {
                    ppEnum = new AD7CodeContextEnum(codeContexts.ToArray());
                    return Constants.S_OK;
                }
            }
            ppEnum = null;
            return Constants.E_FAIL;
        }
Esempio n. 21
0
 public int GetCodeContext(ulong uCodeLocationId, out IDebugCodeContext2 ppCodeContext)
 {
     ppCodeContext = new AD7MemoryAddress(DebuggedProcess.g_Process.Engine, (uint)uCodeLocationId, null);
     return(Constants.S_OK);
 }