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

[dac] Make GetObjectStringData return the needed buffer element count instead of byte count #110540

Merged
merged 4 commits into from
Dec 10, 2024

Conversation

elinor-fung
Copy link
Member

GetObjectStringData is returning the byte count instead of the buffer element count. This is inconsistent with all the other APIs that (optionally) return a needed count which return the buffer element count, not the byte count - for example, for strings specifically: GetAssemblyName, GetMethodDescName, GetObjectClassName, GetMethodTableName, GetFrameName, GetPEFileName.

The only place I found using it (that is, not passing in NULL) is:
https://github.com/dotnet/diagnostics/blob/d1077f536993e79a013c6f97593af84cfbbf0134/src/SOS/Strike/clrma/managedanalysis.cpp#L673-L679
which just treats it as the buffer element count (so creates a larger buffer than necessary)

@mikem8361 / @dotnet/dotnet-diag From what I can tell, this was not actually intended. Is this okay for us to change?

Copy link
Contributor

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

@leculver
Copy link
Contributor

leculver commented Dec 9, 2024

We don't call this in ClrMD, and it doesn't appear on the list of publicly documented methods here: https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/debugging/isosdacinterface-interface. This means that no one at Microsoft is using it.

I do see other folks using it in the wild: https://github.com/lordmilko/ClrDebug/blob/3b49aec309e9ce8a4de142435b11ea71791fdcfe/ClrDebug/Managed/SOS/SOSDacInterface.cs#L1137

I have no strong opinion on changing it or not. I'm just reporting in what I found looking for uses.

@@ -1571,12 +1571,18 @@ ClrDataAccess::GetObjectStringData(CLRDATA_ADDRESS obj, unsigned int count, _Ino
count = needed;

TADDR pszStr = TO_TADDR(obj)+offsetof(StringObject, m_FirstChar);
hr = m_pTarget->ReadVirtual(pszStr, (PBYTE)stringData, count * sizeof(WCHAR), &needed);
ULONG32 bytesRead;
hr = m_pTarget->ReadVirtual(pszStr, (PBYTE)stringData, count * sizeof(WCHAR), &bytesRead);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good as long as ReadVirtual fails on partial reads. I don't remember if it does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, seems like it does not - succeeds as long as any bytesRead > 0.

@elinor-fung elinor-fung merged commit 77caed4 into dotnet:main Dec 10, 2024
84 of 88 checks passed
@elinor-fung elinor-fung deleted the dac-GetObjectStringData branch December 10, 2024 04:54
hez2010 pushed a commit to hez2010/runtime that referenced this pull request Dec 14, 2024
…nt instead of byte count (dotnet#110540)

`GetObjectStringData` is returning the byte count instead of the buffer element count. This is inconsistent with all the other APIs that (optionally) return a needed count which return the buffer element count, not the byte count - for example, for strings specifically: `GetAssemblyName`, `GetMethodDescName`, `GetObjectClassName`, `GetMethodTableName`, `GetFrameName`, `GetPEFileName`.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants