Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SourceBuiltSdkContainsNativeDebugSymbols for 'ilc'. #41752

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests;

public class DebugTests : SdkTests
{
private record ScanResult(string FileName, bool HasDebugInfo, bool HasDebugAbbrevs, bool HasFileSymbols, bool HasGnuDebugLink);
private record ScanResult(string FileName, bool HasDebugInfo, bool HasDebugAbbrevs, bool HasGnuDebugLink);

public DebugTests(ITestOutputHelper outputHelper) : base(outputHelper) { }

Expand All @@ -30,7 +30,7 @@ public void SourceBuiltSdkContainsNativeDebugSymbols()
StringBuilder issueDetails = new();
foreach (var fileName in fileNames)
{
if (!IsElfFile(fileName) || SkipFile(fileName))
if (!IsElfFile(fileName))
{
continue;
}
Expand All @@ -49,11 +49,6 @@ public void SourceBuiltSdkContainsNativeDebugSymbols()
foundIssue = true;
issueDetails.Append($"missing .debug_abbrev section in {fileName}{newLine}");
}
if (!result.HasFileSymbols)
{
foundIssue = true;
issueDetails.Append($"missing FILE symbols in {fileName}{newLine}");
}
if (result.HasGnuDebugLink)
{
foundIssue = true;
Expand All @@ -70,14 +65,6 @@ private bool IsElfFile(string fileName)
return Regex.IsMatch(fileStdOut, @"ELF 64-bit [LM]SB (?:pie )?(?:executable|shared object)");
}

private static bool SkipFile(string path)
{
string fileName = Path.GetFileName(path);

// 'ilc' is a NativeAOT-built application which doesn't meet the expectations set by the test.
return fileName == "ilc";
}

private ScanResult ScanFile(string fileName)
{
string readelfSStdOut = ExecuteHelper.ExecuteProcessValidateExitCode("eu-readelf", $"-S {fileName}", OutputHelper);
Expand All @@ -96,35 +83,11 @@ private ScanResult ScanFile(string fileName)

string readelfsStdOut = ExecuteHelper.ExecuteProcessValidateExitCode("eu-readelf", $"-s {fileName}", OutputHelper);

// Test FILE symbols. These will most likely be removed by anyting that
// manipulates symbol tables because it's generally useless. So a nice test
// that nothing has messed with symbols.
bool hasFileSymbols = readelfsStdOut.Split("\n").Where(ContainsFileSymbols).Any();

// Test that there are no .gnu_debuglink sections pointing to another
// debuginfo file. There shouldn't be any debuginfo files, so the link makes
// no sense either.
bool hasGnuDebuglink = readelfsStdOut.Split("\n").Where(line => line.Contains("] .gnu_debuglink")).Any();

return new ScanResult(fileName, hasDebugInfo, hasDebugAbbrev, hasFileSymbols, hasGnuDebuglink);
}

private bool ContainsFileSymbols(string line)
{
// Try matching against output like this:
// 10: 0000000000000000 0 FILE LOCAL DEFAULT ABS coreclr_resolver.cpp
// 779: 0000000000000000 0 FILE LOCAL DEFAULT ABS header.cpp

var parts = new Regex(@"[ \t\n\r]+").Split(line);
int expectedNumberOfParts = 9;

if (parts.Length < expectedNumberOfParts)
{
return false;
}

var fileNameRegex = new Regex(@"(.*/)?[-_a-zA-Z0-9]+\.(c|cc|cpp|cxx)");
return (parts[3] == "0") && (parts[4] == "FILE") && (parts[5] == "LOCAL") && (parts[6] == "DEFAULT") &&
(parts[7] == "ABS") && (fileNameRegex.IsMatch(parts[8]));
return new ScanResult(fileName, hasDebugInfo, hasDebugAbbrev, hasGnuDebuglink);
}
}
Loading