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

Installer update and fixed lldb's ReadVirtual to support partial reads #3315

Merged
merged 7 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>ccfe6da198c5f05534863bbb1bff66e830e0c6ab</Sha>
</Dependency>
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="7.0.100-rc.1.22407.1">
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="7.0.100-rc.2.22419.24">
<Uri>https://github.com/dotnet/installer</Uri>
<Sha>8f639696e6d57fb09e03e89c6397d913de1231ed</Sha>
<Sha>84d26a070704dc4eb7870f15d44880228bb82cb8</Sha>
</Dependency>
<Dependency Name="Microsoft.AspNetCore.App.Ref.Internal" Version="7.0.0-rc.2.22424.4">
<Uri>https://github.com/dotnet/aspnetcore</Uri>
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<MicrosoftAspNetCoreAppRefInternalVersion>7.0.0-rc.2.22424.4</MicrosoftAspNetCoreAppRefInternalVersion>
<MicrosoftAspNetCoreAppRefVersion>7.0.0-rc.2.22424.4</MicrosoftAspNetCoreAppRefVersion>
<!-- dotnet/installer: Testing version of the SDK. Needed for the signed & entitled host. -->
<MicrosoftDotnetSdkInternalVersion>7.0.100-rc.1.22407.1</MicrosoftDotnetSdkInternalVersion>
<MicrosoftDotnetSdkInternalVersion>7.0.100-rc.2.22419.24</MicrosoftDotnetSdkInternalVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Runtime versions to test -->
Expand All @@ -34,7 +34,7 @@
<MicrosoftAspNetCoreApp60Version>$(MicrosoftNETCoreApp60Version)</MicrosoftAspNetCoreApp60Version>
<!-- The SDK runtime version used to build single-file apps (currently hardcoded) -->
<SingleFileRuntime60Version>6.0.8</SingleFileRuntime60Version>
<SingleFileRuntimeLatestVersion>7.0.0-rc.1.22403.8</SingleFileRuntimeLatestVersion>
<SingleFileRuntimeLatestVersion>7.0.0-rc.1.22411.12</SingleFileRuntimeLatestVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Opt-in/out repo features -->
Expand Down
2 changes: 2 additions & 0 deletions src/SOS/SOS.UnitTests/SOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ public async Task DumpGen(TestConfiguration config)
[SkippableTheory, MemberData(nameof(Configurations))]
public async Task LLDBPluginTests(TestConfiguration config)
{
SkipIfArm(config);

if (OS.Kind == OSKind.Windows || config.IsDesktop || config.RuntimeFrameworkVersionMajor == 1 || OS.IsAlpine)
{
throw new SkipTestException("lldb plugin tests not supported on Windows, Alpine Linux or .NET Core 1.1");
Expand Down
2 changes: 2 additions & 0 deletions src/SOS/SOS.UnitTests/Scripts/StackAndOtherTests.script
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ ENDIF:NETCORE_OR_DOTNETDUMP

# Issue: https://github.com/dotnet/diagnostics/issues/2947
!IFDEF:DOTNETDUMP
!IFDEF:ARM64
!IFDEF:ARM

# Verify DumpStack works
Expand All @@ -218,6 +219,7 @@ VERIFY:.*Child(-SP|EBP|FP)\s+RetAddr\s+Caller, Callee\s+
VERIFY:(.*\s+<HEXVAL>\s+<HEXVAL>\s+\(MethodDesc\s+<HEXVAL>\s+(\+\s*0x<HEXVAL>\s+)?SymbolTestApp\.Program\.Foo4\(System\.String\)\),\s+calling.*\s+)|(.*\s+<HEXVAL>\s+<HEXVAL>\s+\(MethodDesc\s+<HEXVAL>\s+(\+\s*0x<HEXVAL>\s+)?SymbolTestApp\.Program\.Foo2\(Int32, System\.String\)\),\s+calling.*\s+)

ENDIF:ARM
ENDIF:ARM64
ENDIF:DOTNETDUMP

# Verify that IP2MD works (uses IP from ClrStack)
Expand Down
2 changes: 2 additions & 0 deletions src/SOS/SOS.UnitTests/Scripts/StackTests.script
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ VERIFY:.*\s+<HEXVAL>\s+<HEXVAL>\s+System\.String.*

# Issue: https://github.com/dotnet/diagnostics/issues/2947
!IFDEF:DOTNETDUMP
!IFDEF:ARM64
!IFDEF:ARM

# 9) Verify DumpStack works
Expand All @@ -172,4 +173,5 @@ VERIFY:.*Child(-SP|EBP|FP)\s+RetAddr\s+Caller, Callee\s+
VERIFY:.*\s+<HEXVAL>\s+<HEXVAL>\s+\(MethodDesc\s+<HEXVAL>\s+\+\s*0x<HEXVAL>\s+NestedExceptionTest\.Program\.Main\(System\.String\[\]\)\),\s+calling.*

ENDIF:ARM
ENDIF:ARM64
ENDIF:DOTNETDUMP
6 changes: 6 additions & 0 deletions src/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3956,6 +3956,12 @@ DECLARE_API(DumpRuntimeTypes)
"Address", "Domain", "MT");
ExtOut("------------------------------------------------------------------------------\n");

if (!g_snapshot.Build())
{
ExtOut("Unable to build snapshot of the garbage collector state\n");
return E_FAIL;
}

PrintRuntimeTypeArgs pargs;
ZeroMemory(&pargs, sizeof(PrintRuntimeTypeArgs));

Expand Down
74 changes: 61 additions & 13 deletions src/SOS/lldbplugin/services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
#define InvalidTimeStamp 0xFFFFFFFE;
#define InvalidChecksum 0xFFFFFFFF;

#ifndef PAGE_SIZE
#define PAGE_SIZE 0x1000
#endif

#undef PAGE_MASK
#define PAGE_MASK (~(PAGE_SIZE-1))

char *g_coreclrDirectory = nullptr;
char *g_pluginModuleDirectory = nullptr;

Expand Down Expand Up @@ -432,7 +439,7 @@ HRESULT
LLDBServices::GetPageSize(
PULONG size)
{
*size = 4096;
*size = PAGE_SIZE;
return S_OK;
}

Expand Down Expand Up @@ -762,10 +769,21 @@ LLDBServices::ReadVirtual(
ULONG64 offset,
PVOID buffer,
ULONG bufferSize,
PULONG bytesRead)
PULONG pbytesRead)
{
lldb::SBError error;
size_t read = 0;
size_t bytesRead = 0;
ULONG64 nextPageStart;

// Reading 0 bytes must succeed
if (bufferSize == 0)
{
if (pbytesRead)
{
*pbytesRead = 0;
}
return S_OK;
}

// lldb doesn't expect sign-extended address
offset = CONVERT_FROM_SIGN_EXTENDED(offset);
Expand All @@ -776,9 +794,41 @@ LLDBServices::ReadVirtual(
goto exit;
}

read = process.ReadMemory(offset, buffer, bufferSize, error);
// Try the full read and return if successful
bytesRead = process.ReadMemory(offset, buffer, bufferSize, error);
if (error.Success())
{
goto exit;
}

// As it turns out the lldb ReadMemory API doesn't do partial reads and the SOS
// caching depends on that behavior. Round up to the next page boundry and attempt
// to read up to the page boundries.
nextPageStart = (offset + PAGE_SIZE - 1) & PAGE_MASK;

if (!error.Success())
while (bufferSize > 0)
{
size_t size = nextPageStart - offset;
if (size > bufferSize)
{
size = bufferSize;
}
size_t read = process.ReadMemory(offset, buffer, size, error);

bytesRead += read;
offset += read;
buffer = (BYTE*)buffer + read;
bufferSize -= read;
nextPageStart += PAGE_SIZE;

if (!error.Success())
{
break;
}
}

// If the read isn't complete, try reading directly from native modules in the address range.
if (bufferSize > 0)
{
lldb::SBTarget target = process.GetTarget();
if (!target.IsValid())
Expand All @@ -787,8 +837,7 @@ LLDBServices::ReadVirtual(
}

int numModules = target.GetNumModules();
bool found = false;
for (int i = 0; !found && i < numModules; i++)
for (int i = 0; i < numModules; i++)
{
lldb::SBModule module = target.GetModuleAtIndex(i);
int numSections = module.GetNumSections();
Expand All @@ -803,21 +852,20 @@ LLDBServices::ReadVirtual(
lldb::SBData sectionData = section.GetSectionData(offset - loadAddr, bufferSize);
if (sectionData.IsValid())
{
read = sectionData.ReadRawData(error, 0, buffer, bufferSize);
found = true;
break;
bytesRead += sectionData.ReadRawData(error, 0, buffer, bufferSize);
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
goto exit;
}
}
}
}
}

exit:
if (bytesRead)
if (pbytesRead)
{
*bytesRead = read;
*pbytesRead = bytesRead;
}
return error.Success() || (read != 0) ? S_OK : E_FAIL;
return bytesRead > 0 ? S_OK : E_FAIL;
}

HRESULT
Expand Down