Skip to content

Commit

Permalink
TS-30100 add new sample project for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jveihelmann committed Aug 9, 2024
1 parent fe53f70 commit 927bd13
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 32 deletions.
18 changes: 16 additions & 2 deletions Cqse.Teamscale.Profiler.Dotnet.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Profiler", "Profiler\Profiler.vcxproj", "{CC51C2F0-D0F2-41D9-B1D2-5108C1D3B8E6}"
EndProject
Expand All @@ -21,6 +21,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Profiler_Cpp_Test", "Profil
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DumpPdb", "DumpPdb\DumpPdb.csproj", "{BF294B13-B2BB-43B4-9F83-3AA0BE0DC448}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample_Debugging_App", "Sample_Debugging_App\Sample_Debugging_App.csproj", "{084AB86B-40EA-40B1-9B30-43D2619DEF21}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -101,6 +103,18 @@ Global
{BF294B13-B2BB-43B4-9F83-3AA0BE0DC448}.Release|Win32.Build.0 = Release|Any CPU
{BF294B13-B2BB-43B4-9F83-3AA0BE0DC448}.Release|x64.ActiveCfg = Release|Any CPU
{BF294B13-B2BB-43B4-9F83-3AA0BE0DC448}.Release|x64.Build.0 = Release|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Debug|Win32.ActiveCfg = Debug|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Debug|Win32.Build.0 = Debug|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Debug|x64.ActiveCfg = Debug|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Debug|x64.Build.0 = Debug|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Release|Any CPU.Build.0 = Release|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Release|Win32.ActiveCfg = Release|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Release|Win32.Build.0 = Release|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Release|x64.ActiveCfg = Release|Any CPU
{084AB86B-40EA-40B1-9B30-43D2619DEF21}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Profiler/Profiler.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp14</LanguageStandard>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
Expand Down
1 change: 1 addition & 0 deletions Profiler/Profiler.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<LocalDebuggerCommand>C:\Windows\system32\regsvr32.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>$(OutDir)Profiler.dll</LocalDebuggerCommandArguments>
<LocalDebuggerAttach>true</LocalDebuggerAttach>
</PropertyGroup>
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Teamscale Ephemeral .NET Profiler
Teamscale .NET Profiler
[![Build status](https://github.com/cqse/teamscale-profiler-dotnet/actions/workflows/actions.yml/badge.svg)](https://github.com/cqse/teamscale-profiler-dotnet/actions/workflows/actions.yml)
===================================

Lightweight profiler for .NET applications that provides method-level coverage information to support [Test Gap Analysis](https://www.cqse.eu/en/consulting/software-test-control/) in Teamscale.
Lightweight profiler for .NET applications that provides method-level coverage information to support [Test Gap Analysis](https://teamscale.com/test-gap-analysis) in Teamscale.

## System Requirements

Expand All @@ -28,6 +28,8 @@ This way, the integration tests are run correctly against both variants.

Automatic build and testing is performed in a GitHub action.

For debugging tipps, please have a look [here](./documentation/userguide.md).

### Linking against System Libraries

We use `#pragma comment(lib, "LIBRARYNAME.lib")` to specify link-time dependencies directly in the source file
Expand Down
13 changes: 13 additions & 0 deletions Sample_Debugging_App/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"profiles": {
"Sample_Debugging_App": {
"commandName": "Project",
"environmentVariables": {
"CORECLR_ENABLE_PROFILING": "1",
"CORECLR_PROFILER": "{DD0A1BB6-11CE-11DD-8EE8-3F9E55D89593}",
"CORECLR_PROFILER_PATH_64": "C:\\Dev\\teamscale-profiler-dotnet\\Profiler\\bin\\Debug\\Profiler64.dll"
},
"nativeDebugging": true
}
}
}
23 changes: 23 additions & 0 deletions Sample_Debugging_App/SampleDebuggingApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace SampleDebuggingApp
{
/// <summary>
/// Main entry of the debugging app.
/// </summary>
public class DebuggingApp
{
public static void Main()
{

Check warning on line 9 in Sample_Debugging_App/SampleDebuggingApp.cs

View check run for this annotation

cqse.teamscale.io / teamscale-findings

Sample_Debugging_App/SampleDebuggingApp.cs#L8-L9

[New] Interface comment missing https://cqse.teamscale.io/findings/details/teamscale-net-profiler?t=ts%2F30100_sample_debugging_app%3AHEAD&id=1AF4A08B8D52C7797FE8BA02649D8BD3
Console.WriteLine("Hello, World!");
while (true)
{
Thread.Sleep(10000);
TestMethod();
}
}

private static void TestMethod()
{
Console.WriteLine($"TestMethod called.");
}
}
}
10 changes: 10 additions & 0 deletions Sample_Debugging_App/Sample_Debugging_App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
38 changes: 11 additions & 27 deletions documentation/CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
# Debugging (WinDbg)

The following script allows to debug the profiler with `windbg` on Windows 10 with the Windows SDK installed:

SET COR_ENABLE_PROFILING=1
SET COR_PROFILER={DD0A1BB6-11CE-11DD-8EE8-3F9E55D89593}
SET COR_PROFILER_PATH=E:\Profiler\bin\Debug\Profiler64.dll

"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe" "E:\test-data\test-programs\GeneratedTest.exe"

When `windbg` starts up, hit 'Insert and remove breakpoints' (`F9`) and add a breakpoint to

bu Profiler64!CProfilerCallback::Initialize

Then hit 'Go' (`F9`).
The program will stop at the invocation of our initialization and open a source view showing this location.
From this point you can debug with step over/into/out as usual.

### Notes

* `windbg` normally finds the source files automagically.
If it doesn't, setting `File > Source File Path...` probably helps.
* You may [set more specific breakpoints][breakpoints].
* Credits to David Broman and his blog post [explaining how to debug profilers using `windbg`][debugProfilers].

[debugProfilers]: https://blogs.msdn.microsoft.com/davbr/2007/12/11/debugging-your-profiler-i-activation/
[breakpoints]: https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/breakpoint-syntax
# Debugging

The `Sample Debugging App` inside this repository serves to debug the profiler.
To get it going please follow these steps:
* In Visual Studio, select the `Debug` solution config and `x64` as solution platform.
* Build the profiler.
* In the Sample Debugging App properties go to the `Debug` section and select `Open debug launch settings UI`.
* Change `CORECLR_PROFILER_PATH_64` to the path of your `Profiler64.dll`. This path needs to be absolute and should look similar to `C:\\Dev\\teamscale-profiler-dotnet\\Profiler\\bin\\Debug\\Profiler64.dll`.
* Start the Sample Debugging App via Visual Studio.

Your breakpoints in the profiler should now be working correctly and help you with debugging.

0 comments on commit 927bd13

Please sign in to comment.