public override Task <WatchAddressResponse> WatchAddress(WatchAddressRequest request,
                                                                 ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            var          response   = new WatchAddressResponse();
            SbWatchpoint watchpoint = target.WatchAddress(
                request.Address, request.Size, request.Read, request.Write, out SbError error);

            response.Error = new GrpcSbError {
                Success = error.Success(),
                Error   = error.GetCString(),
            };
            if (watchpoint != null)
            {
                response.Watchpoint = new GrpcSbWatchpoint {
                    Id = _watchpointStore.AddObject(watchpoint),
                };
            }
            return(Task.FromResult(response));
        }
 /// <summary>
 /// Checks general preconditions for SBDebugger APIs.
 /// </summary>
 void SbDebuggerPreconditionCheck()
 {
     if (sbDebugger == null)
     {
         ErrorUtils.ThrowError(StatusCode.FailedPrecondition,
                               "Call 'Create' before calling any other API.");
     }
 }
Beispiel #3
0
        public void RemoveObject(long id)
        {
            T obj;

            if (!_objects.TryRemove(id, out obj))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not remove " + typeof(T) + " with id : " + id);
            }
        }
Beispiel #4
0
        public T GetObject(long id)
        {
            T obj;

            if (_objects.TryGetValue(id, out obj))
            {
                return(obj);
            }
            ErrorUtils.ThrowError(StatusCode.Internal,
                                  "Could not get " + typeof(T) + " with id : " + id);
            return(default(T));
        }
        internal static RemoteTarget GetTarget(GrpcSbTarget grpcSbTarget,
                                               ConcurrentDictionary <long, RemoteTarget> targetStore)
        {
            RemoteTarget remoteTarget = null;

            if (!targetStore.TryGetValue(grpcSbTarget.Id, out remoteTarget))
            {
                ErrorUtils.ThrowError(StatusCode.Internal, "Could not find target by ID: "
                                      + grpcSbTarget.Id);
            }
            return(remoteTarget);
        }
Beispiel #6
0
        public long AddObject(T obj)
        {
            long id = Interlocked.Increment(ref _nextId);

            if (_objects.TryAdd(id, obj))
            {
                return(id);
            }
            ErrorUtils.ThrowError(StatusCode.Internal,
                                  "Could not store " + typeof(T) + " with id : " + id);
            return(0);
        }
        internal static SbProcess GetProcess(GrpcSbProcess grpcProcess,
                                             ConcurrentDictionary <int, SbProcess> processStore)
        {
            SbProcess sbProcess = null;

            if (!processStore.TryGetValue(grpcProcess.Id, out sbProcess))
            {
                ErrorUtils.ThrowError(StatusCode.Internal, "Could not find process in store: "
                                      + grpcProcess.Id);
            }
            return(sbProcess);
        }
        public override Task <GetNumModulesResponse> GetNumModules(GetNumModulesRequest request,
                                                                   ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            var response = new GetNumModulesResponse();

            response.Result = target.GetNumModules();
            return(Task.FromResult(response));
        }
        private SbBreakpointLocation GetBreakpointLocation(
            GrpcSbBreakpointLocation grpcBreakpointLocation)
        {
            var breakpoint = RemoteBreakpointRpcServiceImpl.GetBreakpoint(
                targetStore, grpcBreakpointLocation.Breakpoint);
            var breakpointLocation = breakpoint.FindLocationById(grpcBreakpointLocation.Id);

            if (breakpointLocation == null)
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find breakpoint location: " + grpcBreakpointLocation.Id);
            }
            return(breakpointLocation);
        }
        public override Task <DeleteWatchpointResponse> DeleteWatchpoint(
            DeleteWatchpointRequest request, ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }
            bool success  = target.DeleteWatchpoint(request.WatchId);
            var  response = new DeleteWatchpointResponse {
                Success = success
            };

            return(Task.FromResult(response));
        }
        /// <summary>
        /// Set the selected platform.
        /// </summary>
        public override Task <SetSelectedPlatformResponse> SetSelectedPlatform(
            SetSelectedPlatformRequest request, ServerCallContext context)
        {
            SbDebuggerPreconditionCheck();

            // We currently only support one platform, so get it from the manager instead of the
            // request.
            SbPlatform sbPlatform = sbPlatformManager.GetPlatform();

            if (sbPlatform == null)
            {
                ErrorUtils.ThrowError(StatusCode.NotFound,
                                      "Could not find SBPlatform, make sure one has been created.");
            }
            sbDebugger.SetSelectedPlatform(sbPlatform);
            return(Task.FromResult(new SetSelectedPlatformResponse()));
        }
Beispiel #12
0
        public override Task <CreateResponse> Create(CreateRequest request,
                                                     ServerCallContext context)
        {
            // We only support creating one SBPlatform object, fail if there is an attempt to
            // create more.
            if (sbPlatform != null)
            {
                ErrorUtils.ThrowError(StatusCode.FailedPrecondition,
                                      "Creating multiple SBPlatform objects is not supported.");
            }

            sbPlatform = sbPlatformFactory.Create(request.PlatformName);
            if (sbPlatform == null)
            {
                ErrorUtils.ThrowError(StatusCode.Internal, "Could not create SBPlatform.");
            }
            return(Task.FromResult(new CreateResponse()));
        }
Beispiel #13
0
        public override Task <WaitForEventResponse> WaitForEvent(WaitForEventRequest request,
                                                                 ServerCallContext context)
        {
            SbListener listener;

            if (!_listenerStore.TryGetValue(request.Listener.Id, out listener))
            {
                ErrorUtils.ThrowError(
                    StatusCode.Internal,
                    "Could not find listener in store: " + request.Listener.Id);
            }

            SbEvent evnt;
            bool    result   = listener.WaitForEvent(request.NumSeconds, out evnt);
            var     response = new WaitForEventResponse
            {
                Result = result,
            };

            if (result)
            {
                response.Event = new GrpcSbEvent
                {
                    Type              = (uint)evnt.GetEventType(),
                    Description       = evnt.GetDescription(),
                    HasProcessResumed = evnt.GetProcessRestarted(),
                    IsBreakpointEvent = _breakpointApi.EventIsBreakpointEvent(evnt)
                };
                if ((evnt.GetEventType() & EventType.STATE_CHANGED) != 0)
                {
                    response.Event.StateType = StateTypeToProto(evnt.GetStateType());
                }

                if (response.Event.IsBreakpointEvent)
                {
                    response.Event.BreakpointData = new GrpcEventBreakpointData
                    {
                        EventType    = (uint)_breakpointApi.GetBreakpointEventTypeFromEvent(evnt),
                        BreakpointId = _breakpointApi.GetBreakpointFromEvent(evnt).GetId(),
                    };
                }
            }
            return(Task.FromResult(response));
        }
Beispiel #14
0
        public override Task <CreateResponse> Create(CreateRequest request,
                                                     ServerCallContext context)
        {
            var listener = _listenerFactory.Create(request.Name);

            if (!_listenerStore.TryAdd(listener.GetId(), listener))
            {
                ErrorUtils.ThrowError(
                    StatusCode.Internal, "Could not add listener to store: " + listener.GetId());
            }
            var response =
                new CreateResponse {
                Listener = new GrpcSbListener {
                    Id = listener.GetId()
                }
            };

            return(Task.FromResult(response));
        }
        public override Task <GetModuleAtIndexResponse> GetModuleAtIndex(
            GetModuleAtIndexRequest request, ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            var      response = new GetModuleAtIndexResponse();
            SbModule module   = target.GetModuleAtIndex(request.Index);

            if (module != null)
            {
                response.Module = new GrpcSbModule {
                    Id = _moduleStore.AddObject(module)
                };
            }
            return(Task.FromResult(response));
        }
        public override Task <LoadCoreResponse> LoadCore(LoadCoreRequest request,
                                                         ServerCallContext context)
        {
            RemoteTarget target   = GrpcLookupUtils.GetTarget(request.Target, _targetStore);
            SbProcess    process  = target.LoadCore(request.CorePath);
            var          response = new LoadCoreResponse();

            if (process != null)
            {
                if (!_processStore.TryAdd(process.GetUniqueId(), process))
                {
                    ErrorUtils.ThrowError(StatusCode.Internal, "Could not add process to store: " +
                                          process.GetUniqueId());
                }
                response.Process = new GrpcSbProcess {
                    Id = process.GetUniqueId()
                };
            }
            return(Task.FromResult(response));
        }
Beispiel #17
0
        internal static RemoteBreakpoint GetBreakpoint(
            ConcurrentDictionary <long, RemoteTarget> targetStore,
            GrpcSbBreakpoint grpcSbBreakpoint)
        {
            RemoteTarget target = null;

            if (!targetStore.TryGetValue(grpcSbBreakpoint.Target.Id, out target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + grpcSbBreakpoint.Target.Id);
            }
            var breakpoint = target.FindBreakpointById(grpcSbBreakpoint.Id);

            if (breakpoint == null)
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find breakpoint in target: " + grpcSbBreakpoint.Id);
            }
            return(breakpoint);
        }
        /// <summary>
        /// Decreases the ref count of the object referenced by id. If nothing references the
        /// object anymore, it is removed from the store.
        /// Throws RpcException if the object does not exist.
        /// </summary>
        public void RemoveObject(long id)
        {
            lock (_lockObj)
            {
                ObjRef objRef;
                if (!_objects.TryGetValue(id, out objRef))
                {
                    ErrorUtils.ThrowError(StatusCode.Internal,
                                          "Could not remove " + typeof(T) + " with id : " + id);
                    return;
                }

                Debug.Assert(objRef.RefCount > 0);
                if (--objRef.RefCount == 0)
                {
                    _objects.Remove(id);
                    _objectIds.Remove(objRef.Obj);
                }
            }
        }
        public override Task <BreakpointCreateByAddressResponse> BreakpointCreateByAddress(
            BreakpointCreateByAddressRequest request, ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            var response = new BreakpointCreateByAddressResponse();
            RemoteBreakpoint breakpoint = target.BreakpointCreateByAddress(request.Address);

            if (breakpoint != null)
            {
                response.Breakpoint = new GrpcSbBreakpoint {
                    Target = request.Target,
                    Id     = breakpoint.GetId(),
                };
            }
            return(Task.FromResult(response));
        }
        public override Task <AddListenerResponse> AddListener(
            AddListenerRequest request, ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            if (!_listenerStore.TryGetValue(request.Listener.Id, out SbListener listener))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find listener in store: " + request.Listener.Id);
            }

            uint response = target.GetBroadcaster().AddListener(listener, request.EventMask);

            return(Task.FromResult(new AddListenerResponse {
                Result = response
            }));
        }
        public override Task <AttachToProcessWithIDResponse> AttachToProcessWithID(
            AttachToProcessWithIDRequest request, ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            if (!_listenerStore.TryGetValue(request.Listener.Id, out SbListener listener))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find listener in store: " + request.Listener.Id);
            }

            SbProcess process =
                target.AttachToProcessWithID(listener, request.Pid, out SbError error);

            var response =
                new AttachToProcessWithIDResponse {
                Error = new GrpcSbError {
                    Success = error.Success(),
                    Error   = error.GetCString(),
                }
            };

            if (process != null)
            {
                if (!_processStore.TryAdd(process.GetUniqueId(), process))
                {
                    ErrorUtils.ThrowError(StatusCode.Internal, "Could not add process to store: " +
                                          process.GetUniqueId());
                }
                response.Process = new GrpcSbProcess {
                    Id = process.GetUniqueId()
                };
            }
            return(Task.FromResult(response));
        }
        /// <summary>
        /// Create a new LLDB SBDebugger object locally.  This SBDebugger object is then used for
        /// all subsecent requests.
        /// </summary>
        public override Task <CreateResponse> Create(CreateRequest request,
                                                     ServerCallContext context)
        {
            // Lock around sbDebugger.
            lock (thisLock)
            {
                // We only support creating one SBDebugger object, fail if there is an attempt to
                // create more.
                if (sbDebugger != null)
                {
                    ErrorUtils.ThrowError(StatusCode.FailedPrecondition,
                                          "Creating multiple SBDebugger objects is not supported.");
                }

                sbDebugger = sbDebuggerFactory.Create(request.SourceInitFiles);
                if (sbDebugger == null)
                {
                    ErrorUtils.ThrowError(StatusCode.Internal, "Could not create SBDebugger.");
                }
                return(Task.FromResult(new CreateResponse()));
            }
        }
        public override Task <CreateFunctionOffsetBreakpointResponse> CreateFunctionOffsetBreakpoint(
            CreateFunctionOffsetBreakpointRequest request, ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            var response = new CreateFunctionOffsetBreakpointResponse();
            BreakpointErrorPair breakpointErrorPair =
                target.CreateFunctionOffsetBreakpoint(request.SymbolName, request.Offset);

            if (breakpointErrorPair.breakpoint != null)
            {
                response.Breakpoint = new GrpcSbBreakpoint {
                    Target = request.Target,
                    Id     = breakpointErrorPair.breakpoint.GetId(),
                };
            }
            response.Error = (Debugger.Common.BreakpointError)breakpointErrorPair.error;
            return(Task.FromResult(response));
        }
        /// <summary>
        /// Create a new LLDB SBTarget locally, and return a GrpcSbTarget object to the client.
        /// Locally we then map GrpcSbTarget objects to RemoteTarget objects.
        /// </summary>
        public override Task <CreateTargetResponse> CreateTarget(CreateTargetRequest request,
                                                                 ServerCallContext context)
        {
            SbDebuggerPreconditionCheck();
            SbTarget sbTarget = sbDebugger.CreateTarget(request.Filename);

            if (sbTarget == null)
            {
                ErrorUtils.ThrowError(StatusCode.Internal, "Could not create SBTarget.");
            }
            if (!targetStore.TryAdd(sbTarget.GetId(), remoteTargetFactory.Create(sbTarget)))
            {
                ErrorUtils.ThrowError(
                    StatusCode.Internal, "Could not add target to store: " + sbTarget.GetId());
            }
            var grpcSbTarget = new GrpcSbTarget {
                Id = sbTarget.GetId()
            };
            var response = new CreateTargetResponse {
                GrpcSbTarget = grpcSbTarget
            };

            return(Task.FromResult(response));
        }