Beispiel #1
0
        public void CompileSourceMapForSourceMapping(ITestSettings settings)
        {
            this.TestPurpose("Compiles source map debuggee for source mapping.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SourceMappingHelper.OpenAndCompile(this, settings.CompilerSettings, DebuggeeMonikers.SourceMapping.Default);
        }
Beispiel #2
0
        public void MapSpecificFile(ITestSettings settings)
        {
            this.TestPurpose("Validate Specific File Mapping.");

            this.WriteSettings(settings);

            IDebuggee debuggee = SourceMappingHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.SourceMapping.Default);

            // VsDbg is case insensitive on Windows so sometimes stackframe file names might all be lowercase
            StringComparison comparison = settings.DebuggerSettings.DebuggerType == SupportedDebugger.VsDbg ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure");
                LaunchCommand launch = new LaunchCommand(settings.DebuggerSettings, debuggee.OutputPath, false);

                launch.Args.externalConsole = false;

                this.Comment("Setting up Source File Mappings");

                Dictionary <string, string> sourceMappings = new Dictionary <string, string>();
                string pathRoot = Path.GetPathRoot(debuggee.SourceRoot);

                string sourceFileMapping  = Path.Combine(pathRoot, Path.GetRandomFileName(), SourceMappingHelper.Writer);
                string compileFileMapping = Path.Combine(debuggee.SourceRoot, SourceMappingHelper.WriterFolder, SourceMappingHelper.Writer);

                if (PlatformUtilities.IsWindows)
                {
                    // Move file to the location
                    Directory.CreateDirectory(Path.GetDirectoryName(sourceFileMapping));
                    File.Copy(compileFileMapping, sourceFileMapping, true);
                }

                // Drive letter should be lowercase
                sourceMappings.Add(compileFileMapping, sourceFileMapping);

                launch.Args.sourceFileMap = sourceMappings;
                try
                {
                    runner.RunCommand(launch);

                    this.Comment("Set Breakpoint");

                    SourceBreakpoints writerBreakpoints = debuggee.Breakpoints(SourceMappingHelper.Writer, 9);
                    runner.SetBreakpoints(writerBreakpoints);
                    runner.Expects.StoppedEvent(StoppedReason.Breakpoint).AfterConfigurationDone();

                    using (IThreadInspector threadInspector = runner.GetThreadInspector())
                    {
                        IEnumerator <IFrameInspector> frameEnumerator = threadInspector.Stack.GetEnumerator();

                        // Move to first stack item
                        Assert.True(frameEnumerator.MoveNext());
                        this.Comment("Verify path is changed for writer.cpp frame");
                        ValidateMappingToFrame(SourceMappingHelper.Writer, EnsureDriveLetterLowercase(sourceFileMapping), frameEnumerator.Current, comparison);

                        // Move to second stack item
                        Assert.True(frameEnumerator.MoveNext());
                        this.Comment("Verify path is not changed for main.cpp frame.");
                        ValidateMappingToFrame(SourceMappingHelper.Main, EnsureDriveLetterLowercase(Path.Combine(debuggee.SourceRoot, SourceMappingHelper.Main)), frameEnumerator.Current, comparison);

                        writerBreakpoints.Remove(9);
                        runner.SetBreakpoints(writerBreakpoints);
                        this.Comment("Continue to end");

                        runner.Expects.TerminatedEvent().AfterContinue();
                        runner.DisconnectAndVerify();
                    }
                }
                finally
                {
                    if (PlatformUtilities.IsWindows)
                    {
                        // Cleanup the directory
                        if (Directory.Exists(Path.GetDirectoryName(sourceFileMapping)))
                        {
                            Directory.Delete(Path.GetDirectoryName(sourceFileMapping), true);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void MapDirectory(ITestSettings settings)
        {
            this.TestPurpose("Validate Source Mapping.");

            this.WriteSettings(settings);

            IDebuggee debuggee = SourceMappingHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.SourceMapping.Default);

            // VsDbg is case insensitive on Windows so sometimes stackframe file names might all be lowercase
            StringComparison comparison = settings.DebuggerSettings.DebuggerType == SupportedDebugger.VsDbg ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure");
                LaunchCommand launch = new LaunchCommand(settings.DebuggerSettings, debuggee.OutputPath, false, "-fCalling");

                launch.Args.externalConsole = false;

                this.Comment("Setting up Source File Mappings");

                Dictionary <string, string> sourceMappings = new Dictionary <string, string>();
                string pathRoot = Path.GetPathRoot(debuggee.SourceRoot);

                string mgrDirectoryMapping    = Path.Combine(debuggee.SourceRoot, SourceMappingHelper.Manager, Path.GetRandomFileName());
                string writerDirectoryMapping = Path.Combine(pathRoot, Path.GetRandomFileName(), Path.GetRandomFileName());
                string rootDirectoryMapping   = Path.Combine(pathRoot, Path.GetRandomFileName());
                sourceMappings.Add(Path.Combine(debuggee.SourceRoot, SourceMappingHelper.WriterFolder), writerDirectoryMapping);
                sourceMappings.Add(Path.Combine(debuggee.SourceRoot, SourceMappingHelper.ManagerFolder), mgrDirectoryMapping);
                sourceMappings.Add(debuggee.SourceRoot, rootDirectoryMapping);

                launch.Args.sourceFileMap = sourceMappings;

                try
                {
                    if (PlatformUtilities.IsWindows)
                    {
                        // Create all the directories but only some of the files will exist on disk.
                        foreach (var dir in sourceMappings.Values)
                        {
                            Directory.CreateDirectory(dir);
                        }
                        File.Copy(Path.Combine(debuggee.SourceRoot, SourceMappingHelper.WriterFolder, SourceMappingHelper.Writer), Path.Combine(writerDirectoryMapping, SourceMappingHelper.Writer), true);
                        File.Copy(Path.Combine(debuggee.SourceRoot, SourceMappingHelper.Main), Path.Combine(rootDirectoryMapping, SourceMappingHelper.Main), true);
                    }

                    runner.RunCommand(launch);

                    this.Comment("Set Breakpoint");

                    SourceBreakpoints writerBreakpoints  = debuggee.Breakpoints(SourceMappingHelper.Writer, 9);
                    SourceBreakpoints managerBreakpoints = debuggee.Breakpoints(SourceMappingHelper.Manager, 8);
                    runner.SetBreakpoints(writerBreakpoints);
                    runner.SetBreakpoints(managerBreakpoints);
                    runner.Expects.StoppedEvent(StoppedReason.Breakpoint).AfterConfigurationDone();

                    using (IThreadInspector threadInspector = runner.GetThreadInspector())
                    {
                        IEnumerator <IFrameInspector> frameEnumerator = threadInspector.Stack.GetEnumerator();

                        // Move to first stack item
                        Assert.True(frameEnumerator.MoveNext());
                        this.Comment(string.Format(CultureInfo.InvariantCulture, "Verify source path for {0}.", SourceMappingHelper.Writer));
                        // Since file is there, lowercase the drive letter
                        ValidateMappingToFrame(SourceMappingHelper.Writer, EnsureDriveLetterLowercase(Path.Combine(writerDirectoryMapping, SourceMappingHelper.Writer)), frameEnumerator.Current, comparison);


                        // Move to second stack item
                        Assert.True(frameEnumerator.MoveNext());
                        this.Comment(string.Format(CultureInfo.InvariantCulture, "Verify source path for {0}.", SourceMappingHelper.Main));
                        // Since file is there, lowercase the drive letter
                        ValidateMappingToFrame(SourceMappingHelper.Main, EnsureDriveLetterLowercase(Path.Combine(rootDirectoryMapping, SourceMappingHelper.Main)), frameEnumerator.Current, comparison);
                    }
                    runner.Expects.StoppedEvent(StoppedReason.Breakpoint).AfterContinue();

                    using (IThreadInspector threadInspector = runner.GetThreadInspector())
                    {
                        IEnumerator <IFrameInspector> frameEnumerator = threadInspector.Stack.GetEnumerator();

                        // Move to first stack item
                        Assert.True(frameEnumerator.MoveNext());
                        this.Comment(string.Format(CultureInfo.InvariantCulture, "Verify source path for {0}.", SourceMappingHelper.Manager));
                        // Since file is not there, keep what was passed in
                        ValidateMappingToFrame(SourceMappingHelper.Manager, EnsureDriveLetterLowercase(Path.Combine(mgrDirectoryMapping, SourceMappingHelper.Manager)), frameEnumerator.Current, comparison);

                        // Move to second stack item
                        Assert.True(frameEnumerator.MoveNext());
                        this.Comment(string.Format(CultureInfo.InvariantCulture, "Verify source path for {0}.", SourceMappingHelper.Main));
                        // Since file is there, lowercase the drive letter
                        ValidateMappingToFrame(SourceMappingHelper.Main, EnsureDriveLetterLowercase(Path.Combine(rootDirectoryMapping, SourceMappingHelper.Main)), frameEnumerator.Current, comparison);
                    }

                    writerBreakpoints.Remove(9);
                    managerBreakpoints.Remove(8);
                    runner.SetBreakpoints(writerBreakpoints);
                    runner.SetBreakpoints(managerBreakpoints);

                    this.Comment("Continue to end");

                    runner.Expects.TerminatedEvent().AfterContinue();
                    runner.DisconnectAndVerify();
                }
                finally
                {
                    if (PlatformUtilities.IsWindows)
                    {
                        foreach (var dir in sourceMappings.Values)
                        {
                            if (Directory.Exists(dir))
                            {
                                Directory.Delete(dir, recursive: true);
                            }
                        }
                    }
                }
            }
        }