public Factory(JoinableTaskContext taskContext, GrpcDebuggerFactory lldbDebuggerFactory,
                GrpcListenerFactory lldbListenerFactory,
                GrpcPlatformFactory lldbPlatformFactory,
                GrpcPlatformConnectOptionsFactory lldbPlatformConnectOptionsFactory,
                GrpcPlatformShellCommandFactory lldbPlatformShellCommandFactory,
                ILldbAttachedProgramFactory attachedProgramFactory,
                ActionRecorder actionRecorder,
                ModuleFileLoadMetricsRecorder.Factory moduleFileLoadRecorderFactory,
                LldbExceptionManager.Factory exceptionManagerFactory,
                IFileSystem fileSystem, bool fastExpressionEvaluation,
                IModuleFileFinder moduleFileFinder,
                IDumpModulesProvider dumpModulesProvider,
                IModuleSearchLogHolder moduleSearchLogHolder,
                ISymbolSettingsProvider symbolSettingsProvider,
                CoreAttachWarningDialogUtil warningDialog)
 {
     _taskContext         = taskContext;
     _lldbDebuggerFactory = lldbDebuggerFactory;
     _lldbListenerFactory = lldbListenerFactory;
     _lldbPlatformFactory = lldbPlatformFactory;
     _lldbPlatformConnectOptionsFactory = lldbPlatformConnectOptionsFactory;
     _lldbPlatformShellCommandFactory   = lldbPlatformShellCommandFactory;
     _attachedProgramFactory            = attachedProgramFactory;
     _actionRecorder = actionRecorder;
     _moduleFileLoadRecorderFactory = moduleFileLoadRecorderFactory;
     _exceptionManagerFactory       = exceptionManagerFactory;
     _fileSystem = fileSystem;
     _fastExpressionEvaluation = fastExpressionEvaluation;
     _moduleFileFinder         = moduleFileFinder;
     _dumpModulesProvider      = dumpModulesProvider;
     _moduleSearchLogHolder    = moduleSearchLogHolder;
     _symbolSettingsProvider   = symbolSettingsProvider;
     _warningDialog            = warningDialog;
 }
 public DebugSessionLauncher(
     JoinableTaskContext taskContext, GrpcDebuggerFactory lldbDebuggerFactory,
     GrpcListenerFactory lldbListenerFactory, GrpcPlatformFactory lldbPlatformFactory,
     GrpcPlatformConnectOptionsFactory lldbPlatformConnectOptionsFactory,
     GrpcPlatformShellCommandFactory lldbPlatformShellCommandFactory,
     ILldbAttachedProgramFactory attachedProgramFactory, IDebugEngine3 debugEngine,
     LaunchOption launchOption, ActionRecorder actionRecorder,
     ModuleFileLoadMetricsRecorder.Factory moduleFileLoadRecorderFactory,
     string coreFilePath, string executableFileName, string executableFullPath,
     LldbExceptionManager.Factory exceptionManagerFactory, IFileSystem fileSystem,
     bool fastExpressionEvaluation, IModuleFileFinder moduleFileFinder,
     IDumpModulesProvider dumpModulesProvider, IModuleSearchLogHolder moduleSearchLogHolder,
     ISymbolSettingsProvider symbolSettingsProvider,
     CoreAttachWarningDialogUtil warningDialog, IVsiGameLaunch gameLaunch)
 {
     _taskContext         = taskContext;
     _lldbDebuggerFactory = lldbDebuggerFactory;
     _lldbListenerFactory = lldbListenerFactory;
     _lldbPlatformFactory = lldbPlatformFactory;
     _lldbPlatformConnectOptionsFactory = lldbPlatformConnectOptionsFactory;
     _lldbPlatformShellCommandFactory   = lldbPlatformShellCommandFactory;
     _attachedProgramFactory            = attachedProgramFactory;
     _debugEngine             = debugEngine;
     _exceptionManagerFactory = exceptionManagerFactory;
     _fileSystem = fileSystem;
     _fastExpressionEvaluation      = fastExpressionEvaluation;
     _launchOption                  = launchOption;
     _actionRecorder                = actionRecorder;
     _moduleFileLoadRecorderFactory = moduleFileLoadRecorderFactory;
     _coreFilePath                  = coreFilePath;
     _executableFileName            = executableFileName;
     _executableFullPath            = executableFullPath;
     _moduleFileFinder              = moduleFileFinder;
     _dumpModulesProvider           = dumpModulesProvider;
     _moduleSearchLogHolder         = moduleSearchLogHolder;
     _symbolSettingsProvider        = symbolSettingsProvider;
     _warningDialog                 = warningDialog;
     _gameLaunch = gameLaunch;
 }
        /// <summary>
        /// Creates a new debug engine factory.
        /// </summary>
        /// <param name="self">The external identity of the debug engine.</param>
        public virtual IDebugEngineFactory CreateDebugEngineFactory()
        {
            ServiceManager serviceManager = CreateServiceManager();

            GetJoinableTaskContext().ThrowIfNotOnMainThread();

            var vsExpressionCreator = new VsExpressionCreator();

            if (GetVsiService().Options.LLDBVisualizerSupport == LLDBVisualizerSupport.ENABLED)
            {
                GetNatvis().VisualizerScanner.LoadProjectFiles();
            }

            var debugEngineCommands = new DebugEngineCommands(
                GetJoinableTaskContext(), GetNatvis(),
                GetVsiService().Options.LLDBVisualizerSupport == LLDBVisualizerSupport.ENABLED);

            var actionRecorder           = new ActionRecorder(GetDebugSessionMetrics());
            var backgroundProcessFactory = new BackgroundProcess.Factory();

            var processFactory = new ManagedProcess.Factory();
            var binaryFileUtil = new ElfFileUtil(processFactory);
            var lldbModuleUtil = new LldbModuleUtil();

            var symbolServerRequestHandler = new WebRequestHandler()
            {
                AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
                UseDefaultCredentials  = true,
                CachePolicy            = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore),
            };
            var symbolServerHttpClient = new HttpClient(symbolServerRequestHandler);
            var symbolPathParser       = new SymbolPathParser(
                GetFileSystem(), binaryFileUtil, symbolServerHttpClient,
                new CrashReportClient(GetCloudRunner()),
                SDKUtil.GetDefaultSymbolCachePath(), SDKUtil.GetDefaultSymbolStorePath(),
                YetiConstants.SymbolServerExcludeList);
            IModuleFileFinder        moduleFileFinder        = new ModuleFileFinder(symbolPathParser);
            IModuleFileLoaderFactory moduleFileLoaderFactory = new ModuleFileLoader.Factory();

            var moduleFileLoadRecorderFactory =
                new ModuleFileLoadMetricsRecorder.Factory(lldbModuleUtil, moduleFileFinder);

            var symbolLoaderFactory =
                new SymbolLoader.Factory(lldbModuleUtil, binaryFileUtil, moduleFileFinder);
            var binaryLoaderFactory = new BinaryLoader.Factory(lldbModuleUtil, moduleFileFinder);

            var cancelableTaskFactory = GetCancelableTaskFactory();

            var exceptionManagerFactory =
                new LldbExceptionManager.Factory(LinuxSignals.GetDefaultSignalsMap());

            DebugModule.Factory debugModuleFactory =
                GetFactoryDecorator().Decorate(new DebugModule.Factory(
                                                   cancelableTaskFactory, actionRecorder, moduleFileLoadRecorderFactory,
                                                   lldbModuleUtil, GetSymbolSettingsProvider()));
            var debugModuleCacheFactory   = new DebugModuleCache.Factory(GetDispatcher());
            var debugMemoryContextFactory =
                GetFactoryDecorator().Decorate(new DebugMemoryContext.Factory());

            var debugDocumentContextFactory =
                GetFactoryDecorator().Decorate(new DebugDocumentContext.Factory());

            var debugCodeContextFactory = GetFactoryDecorator().Decorate(
                new DebugCodeContext.Factory(debugMemoryContextFactory));

            var varInfoEnumFactory =
                GetFactoryDecorator().Decorate <IVariableInformationEnumFactory>(
                    new VariableInformationEnum.Factory(GetTaskExecutor()));

            var concreteChildrenProviderFactory = new ChildrenProvider.Factory();
            var childrenProviderFactory         = GetFactoryDecorator().Decorate <IChildrenProviderFactory>(
                concreteChildrenProviderFactory);

            // TODO: Add test for this: (internal)
            bool asyncInterfacesEnabled =
                GetVsiService().Options.AsyncInterfaces == AsyncInterfaces.ENABLED;

            var debugPropertyFactory = GetFactoryDecorator().Decorate(new DebugProperty.Factory(
                                                                          varInfoEnumFactory, childrenProviderFactory, debugCodeContextFactory,
                                                                          vsExpressionCreator, GetTaskExecutor()));
            var debugPropertyAsyncFactory =
                GetFactoryDecorator().Decorate(new DebugAsyncProperty.Factory(
                                                   varInfoEnumFactory, childrenProviderFactory, debugCodeContextFactory,
                                                   vsExpressionCreator, GetTaskExecutor()));

            var createDebugPropertyDelegate =
                asyncInterfacesEnabled
                ?(CreateDebugPropertyDelegate)
                debugPropertyAsyncFactory.Create : debugPropertyFactory.Create;

            concreteChildrenProviderFactory.Initialize(createDebugPropertyDelegate);

            var asyncEvaluatorFactory =
                GetFactoryDecorator().Decorate(new AsyncExpressionEvaluator.Factory(
                                                   createDebugPropertyDelegate, GetVarInfoBuilder(), vsExpressionCreator,
                                                   new ErrorDebugProperty.Factory(), debugEngineCommands,
                                                   GetVsiService().Options, GetExpressionEvaluationRecorder(), GetTimeSource()));

            var debugExpressionFactory = GetFactoryDecorator().Decorate(
                new DebugExpression.Factory(asyncEvaluatorFactory, GetTaskExecutor()));
            var debugAsyncExpressionFactory = GetFactoryDecorator().Decorate(
                new DebugAsyncExpression.Factory(asyncEvaluatorFactory, GetTaskExecutor()));
            var debugExpressionCreator =
                asyncInterfacesEnabled
                ?(CreateDebugExpressionDelegate)
                debugAsyncExpressionFactory.Create : debugExpressionFactory.Create;
            var registerSetsBuilderFactory = GetFactoryDecorator().Decorate(
                new RegisterSetsBuilder.Factory(GetVariableInformationFactory()));
            var debugStackFrameFactory = GetFactoryDecorator().Decorate(new DebugStackFrame.Factory(
                                                                            debugDocumentContextFactory, childrenProviderFactory, debugCodeContextFactory,
                                                                            debugExpressionCreator, GetVariableInformationFactory(), varInfoEnumFactory,
                                                                            registerSetsBuilderFactory, GetTaskExecutor()));
            var debugStackFrameFactoryAsync =
                GetFactoryDecorator().Decorate(new DebugStackFrameAsync.Factory(
                                                   debugDocumentContextFactory, childrenProviderFactory, debugCodeContextFactory,
                                                   debugExpressionCreator, GetVariableInformationFactory(), varInfoEnumFactory,
                                                   registerSetsBuilderFactory, GetTaskExecutor()));
            var debugStackFrameCreator =
                asyncInterfacesEnabled ?(CreateDebugStackFrameDelegate)
                debugStackFrameFactoryAsync.Create : debugStackFrameFactory.Create;
            var debugThreadFactory = GetFactoryDecorator().Decorate(new DebugThread.Factory(
                                                                        GetFactoryDecorator().Decorate(new FrameEnumFactory()), _taskExecutor));
            var debugThreadAsyncFactory =
                GetFactoryDecorator().Decorate(new DebugThreadAsync.Factory(
                                                   GetFactoryDecorator().Decorate(new FrameEnumFactory()), _taskExecutor));
            var debugThreadCreator = asyncInterfacesEnabled ?(CreateDebugThreadDelegate)
                                     debugThreadAsyncFactory.Create : debugThreadFactory.Create;
            var gameletFactory        = GetGameletClientFactory();
            var launchParamsConverter =
                new LaunchGameParamsConverter(GetSdkConfigFactory(), new QueryParametersParser());
            var gameLaunchManager = new GameLaunchBeHelper(gameletFactory.Create(GetCloudRunner()),
                                                           launchParamsConverter);
            var debugProgramFactory =
                GetFactoryDecorator().Decorate <IDebugProgramFactory>(new DebugProgram.Factory(
                                                                          GetJoinableTaskContext(),
                                                                          GetFactoryDecorator().Decorate(new DebugDisassemblyStream.Factory(
                                                                                                             debugCodeContextFactory, debugDocumentContextFactory)),
                                                                          debugDocumentContextFactory, debugCodeContextFactory,
                                                                          GetFactoryDecorator().Decorate(new ThreadEnumFactory()),
                                                                          GetFactoryDecorator().Decorate(new ModuleEnumFactory()),
                                                                          GetFactoryDecorator().Decorate(new CodeContextEnumFactory())));
            var breakpointErrorEnumFactory =
                GetFactoryDecorator().Decorate(new BreakpointErrorEnumFactory());
            var boundBreakpointEnumFactory =
                GetFactoryDecorator().Decorate(new BoundBreakpointEnumFactory());
            var breakpointManagerFactory = new LldbBreakpointManager.Factory(
                GetJoinableTaskContext(),
                GetFactoryDecorator().Decorate(new DebugPendingBreakpoint.Factory(
                                                   GetJoinableTaskContext(),
                                                   GetFactoryDecorator().Decorate(new DebugBoundBreakpoint.Factory(
                                                                                      debugDocumentContextFactory, debugCodeContextFactory,
                                                                                      GetFactoryDecorator().Decorate(new DebugBreakpointResolution.Factory()))),
                                                   breakpointErrorEnumFactory, boundBreakpointEnumFactory)),
                GetFactoryDecorator().Decorate(new DebugWatchpoint.Factory(
                                                   GetJoinableTaskContext(),
                                                   GetFactoryDecorator().Decorate(new DebugWatchpointResolution.Factory()),
                                                   breakpointErrorEnumFactory, boundBreakpointEnumFactory)));
            var eventManagerFactory =
                new LldbEventManager.Factory(boundBreakpointEnumFactory, GetJoinableTaskContext());
            var lldbDebuggerFactory               = new GrpcDebuggerFactory();
            var lldbListenerFactory               = new GrpcListenerFactory();
            var lldbPlatformShellCommandFactory   = new GrpcPlatformShellCommandFactory();
            var lldbPlatformFactory               = new GrpcPlatformFactory();
            var lldbPlatformConnectOptionsFactory = new GrpcPlatformConnectOptionsFactory();
            var grpcInterceptors = CreateGrpcInterceptors(GetVsiService().DebuggerOptions);
            var vsOutputWindow   =
                serviceManager.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
            var callInvokerFactory      = new PipeCallInvokerFactory();
            var transportSessionFactory =
                new LldbTransportSession.Factory(new MemoryMappedFileFactory());
            var yetiTransport = new YetiDebugTransport(
                GetJoinableTaskContext(), transportSessionFactory, callInvokerFactory,
                new GrpcConnectionFactory(GetJoinableTaskContext().Factory,
                                          grpcInterceptors.ToArray()),
                GetTaskExecutor().CancelAsyncOperationIfRequested, processFactory, GetDialogUtil(),
                vsOutputWindow, GetVsiService());

            var testClientLauncherFactory = new ChromeClientsLauncher.Factory(
                new ChromeClientLaunchCommandFormatter(GetJsonUtil()), GetSdkConfigFactory(),
                GetChromeLauncher(backgroundProcessFactory));

            var exitDialogUtil         = new ExitDialogUtil(GetDialogUtil(), GetDialogExecutionContext());
            var preflightBinaryChecker =
                new PreflightBinaryChecker(GetFileSystem(), binaryFileUtil);
            var lldbShell = serviceManager.GetGlobalService(typeof(SLLDBShell)) as ILLDBShell;
            var attachedProgramFactory =
                GetFactoryDecorator().Decorate <ILldbAttachedProgramFactory>(
                    new LldbAttachedProgram.Factory(
                        GetJoinableTaskContext(),
                        GetFactoryDecorator().Decorate <IDebugEngineHandlerFactory>(
                            new DebugEngineHandler.Factory(GetJoinableTaskContext())),
                        GetTaskExecutor(), eventManagerFactory, debugProgramFactory,
                        debugModuleCacheFactory, debugModuleFactory, debugThreadCreator,
                        debugStackFrameCreator, lldbShell, breakpointManagerFactory,
                        symbolLoaderFactory, binaryLoaderFactory, moduleFileLoaderFactory));
            bool fastExpressionEvaluation = GetVsiService().Options.FastExpressionEvaluation ==
                                            FastExpressionEvaluation.ENABLED;
            var dumpModulesProvider     = new DumpModulesProvider(GetFileSystem());
            var moduleSearchLogHolder   = new ModuleSearchLogHolder();
            var coreAttachWarningDialog = new CoreAttachWarningDialogUtil(
                GetJoinableTaskContext(),
                GetDialogUtil());
            var debugSessionLauncherFactory = new DebugSessionLauncher.Factory(
                GetJoinableTaskContext(), lldbDebuggerFactory, lldbListenerFactory,
                lldbPlatformFactory, lldbPlatformConnectOptionsFactory,
                lldbPlatformShellCommandFactory, attachedProgramFactory, actionRecorder,
                moduleFileLoadRecorderFactory, exceptionManagerFactory, GetFileSystem(),
                fastExpressionEvaluation, moduleFileFinder, dumpModulesProvider,
                moduleSearchLogHolder, GetSymbolSettingsProvider(), coreAttachWarningDialog);
            var paramsFactory    = new Params.Factory(GetJsonUtil());
            var vsiLaunchFactory = new VsiGameLaunchFactory(gameletFactory.Create(GetCloudRunner()),
                                                            GetCancelableTaskFactory(),
                                                            gameLaunchManager, actionRecorder,
                                                            GetDialogUtil());
            var gameLauncher = new GameLauncher(gameletFactory.Create(GetCloudRunner()),
                                                GetVsiService(), launchParamsConverter,
                                                GetCancelableTaskFactory(), actionRecorder,
                                                GetDialogUtil(), vsiLaunchFactory);

            var remoteCommand = new RemoteCommand(processFactory);
            var remoteFile    = new RemoteFile(processFactory);
            var remoteDeploy  = new RemoteDeploy(remoteCommand, remoteFile, processFactory,
                                                 GetFileSystem());
            bool deployLldbServer       = IsInternalEngine();
            IDebugEngineFactory factory = new DebugEngine.Factory(
                GetJoinableTaskContext(), serviceManager, GetDebugSessionMetrics(), yetiTransport,
                actionRecorder, symbolServerHttpClient, moduleFileLoadRecorderFactory,
                moduleFileFinder, testClientLauncherFactory, GetNatvis(),
                GetNatvisDiagnosticLogger(), exitDialogUtil, preflightBinaryChecker,
                debugSessionLauncherFactory, paramsFactory, remoteDeploy, cancelableTaskFactory,
                GetDialogUtil(), GetNatvisLoggerOutputWindowListener(), GetSolutionExplorer(),
                debugEngineCommands,
                GetDebugEventCallbackDecorator(GetVsiService().DebuggerOptions),
                GetSymbolSettingsProvider(), deployLldbServer, gameLauncher);

            return(GetFactoryDecorator().Decorate(factory));
        }
        DebugSessionLauncher.Factory CreateLauncherFactory(bool stadiaPlatformAvailable,
                                                           PlatformFactoryFakeConnectRecorder
                                                           connectRecorder = null)
        {
            _debuggerFactory =
                new GrpcDebuggerFactoryFake(new TimeSpan(0), stadiaPlatformAvailable);
            _platformFactory = new GrpcPlatformFactoryFake(connectRecorder);
            var taskContext = new JoinableTaskContext();

            _listenerFactory = new GrpcListenerFactoryFake();

            // If stadiaPlatformAvailable is True the DebugSessionLauncher will connect
            // to the platform 'remote-stadia', otherwise it will use 'remote-linux'
            var platformName = stadiaPlatformAvailable
                ? "remote-stadia"
                : "remote-linux";

            _platformFactory.AddFakeProcess(platformName, _gameBinary, 44);
            var exceptionManagerFactory =
                new LldbExceptionManager.Factory(new Dictionary <int, Signal>());
            var connectOptionsFactory       = new GrpcPlatformConnectOptionsFactory();
            var platformShellCommandFactory = new GrpcPlatformShellCommandFactory();

            var childAdapterFactory = new RemoteValueChildAdapter.Factory();
            var varInfoFactory      = new LLDBVariableInformationFactory(childAdapterFactory);

            var taskExecutor = new TaskExecutor(taskContext.Factory);

            var debugCodeContextFactory =
                new DebugCodeContext.Factory(new DebugMemoryContext.Factory());

            var debugDocumentContextFactory = new DebugDocumentContext.Factory();
            var threadsEnumFactory          = new ThreadEnumFactory();
            var moduleEnumFactory           = new ModuleEnumFactory();
            var frameEnumFactory            = new FrameEnumFactory();
            var codeContextEnumFactory      = new CodeContextEnumFactory();

            var lldbModuleUtil   = new LldbModuleUtil();
            var moduleFileFinder = Substitute.For <IModuleFileFinder>();
            var moduleFileLoadRecorderFactory =
                new ModuleFileLoadMetricsRecorder.Factory(lldbModuleUtil, moduleFileFinder);
            var mockBinaryFileUtil     = Substitute.For <IBinaryFileUtil>();
            var lldbShell              = Substitute.For <ILLDBShell>();
            var actionRecorder         = new ActionRecorder(Substitute.For <IMetrics>());
            var symbolSettingsProvider = Substitute.For <ISymbolSettingsProvider>();
            var attachedProgramFactory = new LldbAttachedProgram.Factory(
                taskContext, new DebugEngineHandler.Factory(taskContext), taskExecutor,
                new LldbEventManager.Factory(new BoundBreakpointEnumFactory(), taskContext),
                new DebugProgram.Factory(taskContext,
                                         new DebugDisassemblyStream.Factory(
                                             debugCodeContextFactory, debugDocumentContextFactory),
                                         debugDocumentContextFactory, debugCodeContextFactory,
                                         threadsEnumFactory, moduleEnumFactory,
                                         codeContextEnumFactory),
                new DebugModuleCache.Factory(new SynchronousDispatcher()),
                new DebugModule.Factory(
                    FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false),
                    actionRecorder, moduleFileLoadRecorderFactory, lldbModuleUtil,
                    symbolSettingsProvider),
                new DebugThread.Factory(frameEnumFactory, taskExecutor).Create,
                new DebugStackFrame.Factory(debugDocumentContextFactory,
                                            new ChildrenProvider.Factory(), debugCodeContextFactory,
                                            Substitute.For <DebugExpression.Factory>().Create,
                                            varInfoFactory,
                                            new VariableInformationEnum.Factory(taskExecutor),
                                            new RegisterSetsBuilder.Factory(varInfoFactory),
                                            taskExecutor).Create, lldbShell,
                new LldbBreakpointManager.Factory(taskContext,
                                                  new DebugPendingBreakpoint.Factory(
                                                      taskContext,
                                                      new DebugBoundBreakpoint.Factory(
                                                          debugDocumentContextFactory,
                                                          debugCodeContextFactory,
                                                          new DebugBreakpointResolution.Factory()),
                                                      new BreakpointErrorEnumFactory(),
                                                      new BoundBreakpointEnumFactory()),
                                                  new DebugWatchpoint.Factory(
                                                      taskContext,
                                                      new DebugWatchpointResolution.Factory(),
                                                      new BreakpointErrorEnumFactory(),
                                                      new BoundBreakpointEnumFactory())),
                new SymbolLoader.Factory(lldbModuleUtil, mockBinaryFileUtil, moduleFileFinder),
                new BinaryLoader.Factory(lldbModuleUtil, moduleFileFinder),
                Substitute.For <IModuleFileLoaderFactory>());

            var coreAttachWarningDialog = new CoreAttachWarningDialogUtil(
                taskContext, Substitute.For <IDialogUtil>());

            return(new DebugSessionLauncher.Factory(
                       taskContext, _debuggerFactory, _listenerFactory, _platformFactory,
                       connectOptionsFactory, platformShellCommandFactory, attachedProgramFactory,
                       actionRecorder, moduleFileLoadRecorderFactory, exceptionManagerFactory, _fileSystem,
                       false, moduleFileFinder, new DumpModulesProvider(_fileSystem),
                       new ModuleSearchLogHolder(), symbolSettingsProvider, coreAttachWarningDialog));
        }