public int GetCodeContext(ulong codeLocationId, out IDebugCodeContext2 codeContext)
        {
            // The codeContext is used, among other things, to link assembly instructions and
            // source code. The "Go To Source Code" functionality in disassembly view needs this
            // to be properly implemented.
            IDebugDocumentContext2 documentContext = null;

            if (_lineEntryCache.TryGetValue(codeLocationId, out LineEntryInfo lineEntry))
            {
                documentContext = _documentContextFactory.Create(lineEntry);
            }
            else
            {
                SbAddress address = _target.ResolveLoadAddress(codeLocationId);
                if (address != null)
                {
                    lineEntry       = address.GetLineEntry();
                    documentContext = _documentContextFactory.Create(lineEntry);
                }
            }

            string AddressToFuncName() =>
            _target.ResolveLoadAddress(codeLocationId)?.GetFunction()?.GetName() ??
            _codeContextName;

            codeContext = _codeContextFactory.Create(codeLocationId,
                                                     new Lazy <string>(AddressToFuncName),
                                                     documentContext, Guid.Empty);
            return(VSConstants.S_OK);
        }
        public override Task <ResolveLoadAddressResponse> ResolveLoadAddress(
            ResolveLoadAddressRequest request, ServerCallContext context)
        {
            RemoteTarget target   = GrpcLookupUtils.GetTarget(request.Target, _targetStore);
            var          response = new ResolveLoadAddressResponse();
            SbAddress    address  = target.ResolveLoadAddress(request.Address);

            if (address != null)
            {
                response.Address = new GrpcSbAddress {
                    Id = _addressStore.AddObject(address),
                };
            }
            return(Task.FromResult(response));
        }
        public void GetCodeContext()
        {
            const ulong newAddress = 0x123456789a;

            SbAddress address         = Substitute.For <SbAddress>();
            var       documentContext = Substitute.For <IDebugDocumentContext2>();
            var       newCodeContext  = Substitute.For <IDebugCodeContext2>();

            _mockTarget.ResolveLoadAddress(newAddress).Returns(address);
            _documentContextFactory.Create(address.GetLineEntry()).Returns(documentContext);
            _codeContextFactory
            .Create(newAddress, Arg.Any <Lazy <string> >(), documentContext, Guid.Empty)
            .Returns(newCodeContext);

            Assert.AreEqual(VSConstants.S_OK, _disassemblyStream.GetCodeContext(
                                newAddress, out IDebugCodeContext2 codeContext));
            Assert.AreEqual(newCodeContext, codeContext);
        }