Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

[SOS][Linux] Support of reading local variables from portable PDB #5897

Conversation

lucenticus
Copy link

This pull request implements initial support of reading local variables from portable PDB for clrstack -i command. To read variables we need System.Diagnostics.Debug.SymbolReader.dll with method GetLocalVariableName form the issue: https://github.com/dotnet/corefx/issues/9570.
Please pay in attention on FIXME src/ToolBox/SOS/Strike/util.cpp:6386: if we trying to release memory, then we get SIGABRT ("free(): invalid pointer"). @mikem8361, @janvorli could you advise the best way to release memory from managed code?
Related issue: https://github.com/dotnet/coreclr/issues/5809
CC @Dmitri-Botcharnikov @seanshpark @chunseoklee

if (Status != S_OK)
return Status;
// FIXME: we need to find a way to release memory after getting string from managed code.
WCHAR *wszParamName = new (std::nothrow) WCHAR[mdNameLen];
Copy link
Member

Choose a reason for hiding this comment

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

The managed code shouldn't free this memory; it should be freed when the function returns. The managed code shouldn't save this pointer in any global state. If it is, then maybe the managed code needs to change.

If you absolutely have to save the string in the managed code, then you could allocate is a bstr with SysAllocString and use Marshal.FreeBSTR to free it managed code. But I don't remember if this is supported in the xplat platforms.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like @Dmitri-Botcharnikov is changing GetLocalVariableName to return a BSTR for the name so my comment is moot other than using SysFreeString to free it in this native code. I don't remember if we properly support BSTRs on the xplat platforms. It still may be simpler to allocate a buffer like the current code and free it in native code. The managed code just copies the name string to the incoming buffer.

@lucenticus
Copy link
Author

@mikem8361 SysFreeString works fine, thanks! I've slightly change the code to use SysAllocStringLen for allocation.

@mikem8361
Copy link
Member

LGTM

Status = CreateDelegate(hostHandle, domainId, SymbolReaderDllName,
SymbolReaderClassName, "GetLocalVariableName",
(void **)&getLocalVariableNameDelegate);
IfFailRet(Status);
Copy link
Member

Choose a reason for hiding this comment

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

This isn't needed, since you're returning Status next anyway.

Copy link
Member

Choose a reason for hiding this comment

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

BTW, it looks like in this change and in some previous changes, the following pattern has been added:

Status = Something();
IfFailRet(Status);

whereas the convention is normally:

IfFailRet(Something());

@lucenticus
Copy link
Author

@adityamandaleeka, thanks for review!

@adityamandaleeka
Copy link
Member

adityamandaleeka commented Jun 23, 2016

@dotnet-bot
test Linux ARM Emulator Cross Debug Build
test Linux ARM Emulator Cross Release Build

Some of these jobs are failing with ./tests/scripts/arm32_ci_script.sh: not found. cc: @prajwal-aithal

@prajwal-aithal
Copy link

@adityamandaleeka The ARM CI check was included yesterday. This error has been seen in PRs that were made (or rebased on earlier masters) before the check was introduced. Other PRs initiated after the CI check was introduced work fine. There must be an issue with pulling the latest master and merging the current PR into that version when the CI begins the check (this is just a hypothesis). A quick fix is to rebase over the latest master and force push to the branch again. I will look into why exactly this error is happening and fix it soon.

cc @jashook

@jashook
Copy link

jashook commented Jun 24, 2016

@adityamandaleeka this is a CI issue caused from merging the wrong hash. @mmitche can explain better. The arm legs are not the problem, you can ignore the errors. Also @prajwal-aithal you can safely ignore these issues, they are unrelated to your changes.

@adityamandaleeka
Copy link
Member

Thanks @jashook. I'll merge this PR.

@adityamandaleeka adityamandaleeka merged commit b5ab114 into dotnet:master Jun 24, 2016
@lucenticus lucenticus deleted the clrstack_local_vars_portable_pdb_reader branch June 24, 2016 05:31
@lucenticus
Copy link
Author

@adityamandaleeka @mikem8361 Could you merge PR dotnet/corefx#9571 too? My PR using updated System.Diagnostics.Debug.SymbolReader.dll for reading locals.

@mmitche
Copy link
Member

mmitche commented Jun 24, 2016

@adityamandaleeka @mikem8361 dotnet/dotnet-ci#339

That has a workaround. I hope to roll out the fix this weekend.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…tnet/coreclr#5897)

* Initial support of reading local variables from portable pdb using System.Diagnostics.Debug.SymbolReader.dll

* Use SysAllocString and SysFreeString for memory management

* Fix coding style after review


Commit migrated from dotnet/coreclr@b5ab114
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants