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
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
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
69 changes: 57 additions & 12 deletions src/SOS/lldbplugin/services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,15 +757,30 @@ LLDBServices::GetContextStackTrace(
// IDebugDataSpaces
//----------------------------------------------------------------------------

#ifndef PAGE_SIZE
#define PAGE_SIZE 0x1000
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
#endif
#define PAGE_MASK (~(PAGE_SIZE-1))

HRESULT
LLDBServices::ReadVirtual(
ULONG64 offset,
PVOID buffer,
ULONG bufferSize,
PULONG bytesRead)
PULONG pbytesRead)
{
lldb::SBError error;
size_t read = 0;
size_t bytesRead = 0;
ULONG64 page;

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 +791,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.
page = (offset + PAGE_SIZE - 1) & PAGE_MASK;
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved

if (!error.Success())
while (bufferSize > 0)
{
size_t size = page - 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;
page += 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 +834,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 +849,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