-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Span: Add debugger viewers to Span<T> and ReadOnlySpan<T> #19629
Comments
@ahsonkhan is this something you are working on? |
Not atm. Would you like me to tackle it? |
I marked it as up for grabs. If you have time to work on it, then let me know and I will assign it to you! |
Hi @karelz, I plan to work on it with a colleague. Have you defined if we need to Override ToString, add debugger viewer or both? Thanks |
@KrzysztofCwalina @jkotas can comment which solution is better ... |
The debugger viewer is the important one to have. I am not sure what ToString would do to be useful. Span is essentially a collection type. We do not have ToString overrides on collection types in general. |
@mramosMS will fix this issue. Thanks |
@mramosMS I sent you collaboration invite. Once you accept (ping me when you do it), I will be able to assign the issue to you (GitHub restrictions/policy). |
@mramosMS are you still working on it? |
Yes, I will work on that the second week of February.
@mramosMS<https://github.com/mramosMS> are you still working on it?
|
I was trying to use my own build of System.Memory (unsuccessfully btw) and figure out that we have two implementations: https://github.com/dotnet/corefx/blob/master/src/System.Memory/src/System/Span.cs and https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Span.cs. How does it work? Thanks |
Hi guys, after building CoreFX, I can't find System.Memory package. Do you know how to generate it? I just found the DLL (at "corefx\bin\runtime\netcoreapp-Windows_NT-Debug-x64\System.Memory.dll"). So, I'm copying it manually to System.Memory package cache folder "C:\Users\myuser.nuget\packages\System.Memory\4.4.0-beta-24913-01\lib\netstandard1.0". It works and I can use it to debug on Visual Studio and see how the debug view works. But it is ugly :) |
@ahsonkhan @jkotas can you please help? |
For a netcoreapp, the System.Memory project contains some Span APIs that type forward to the implementation in mscorlib (Fast Span). The System.Memory csproj file should help clarify since it is a partial facade: https://github.com/dotnet/corefx/blob/master/src/System.Memory/src/System.Memory.csproj#L29 If you look at the Manifest of the System.Memory.dll that gets built, you will see the type forwarding: |
I sent my workaround to @mramosMS, I think it worked for him. |
The Workaround worked to debug the application !!. What is required is to implement DebuggerTypeProxy ?
I sent my workaround to @mramosMS<https://github.com/mramosMS>, I think it worked for him.
|
@KrzysztofCwalina, do you have any insights on implementing DebuggerTypeProxy? |
I implemented such proxy some time ago. It did not work. There was an issue in the debugger that prevented it from working. I don't think the issues have been resolved. |
@fujiy, which particular part are you thinking about implementing? the proxy? If yes, I do understand how proxies work. The particular implementation of the proxy for Span<T> that I implemented simply called this.ToArray(), and it did not work. The reason is that the debugger uses an interpreter in some scenarios and it cannot interpret something about span (which is a very bizarre type). Possibly there is a different way to implement the proxy, but I am not sure what would make the interpreter work. |
Got it. We can try some different ways to retrieve the collection. |
@ahsonkhan for netcoreapp 1.0 the Slow Span is also used? I can't figure out how to generate the System.Memory package Thanks |
@mramosMS, as @KrzysztofCwalina said, most of methods in Span class don't work when called by the debugger interpreter, so I implemented the proxy exposing the _pinnable variable with success. (System.Memory version, the netcoreapp uses mscorlib and the implementation is different) I found a way to test it more easily, instead of changing CoreFX source code, I implemented it with a class in my Console project using a Global Attribute: [assembly: DebuggerTypeProxy(typeof(MySpanDebugView<>), Target = typeof(Span<>))]
So I can build/test/debug quickly. When implementing inside Span class you could remove the Reflection code:
Let me know if it works for you. |
Thanks @jkotas. Opened internal bug 402754. |
Hi guys, I'm afraid I can't make it work for Fast as I thought. I worked in my tests, where I write de Debug Type proxy in my console app. But when I copy the same code to CoreClr and build it, i doesn't work. VS just says that can't evaluate it. |
The package is on myget currently: For type forwarding, look at the csproj and ref assembly: You will likely need to add the type in coreclr as well: |
Hi @ahsonkhan. I did that to Slow Span. But I didn't figure out how System.Memory.dll for Fast Span is built (the one used at runtime). How it generates the type forward to System.Private.CoreLib. It currently contains type-forward just for Span and ReadOnlySpan The best guess I have is that it generates autommatically. But I still didn't figure out how to make corefx build consume the packages generated by my coreclr build. Here is explained (a bit outdated) how to do that, but I don't want to (and won't be able) to send a PR to CoreClr and wait you merge it, before I know if it will work. https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/adding_new_public_apis.md |
Correct.
|
@fujiy, do you have any updates for fast span or maybe some more questions? |
I'm still trying to build coreclr/corefx with 2017 without success, my computer has just 100GB so I can't install both 2015 and 2017. |
Are you able to build using the command line instead? Edit: Ignore, I just saw the issue you linked to. |
Do you know why when running the application it loads the System.Private.CoreLib.ni.dll from
Instead of
I didn't find out how to generate the Microsoft.NerCore.App package |
@ahsonkhan I guess I can't implement it to Fast Span, because VIL doesn't support calling methods from Unsafe class, they are implemented by EE, e.g.:
I also tried to use GCHandle without success |
@mellinoe, can you help with clarifying this?
@jkotas, @plnelson, is this something that we need the VS debugger team to help with? |
@ahsonkhan, @plnelson created an internal bug 286592, I don't know if it includes the methods generated by EE. I'm facing some issues using my coreclr build, when I run dotnet publish and execute the result, I receive:
I could make it work copying the content of my coreclr\bin\Product\Windows_NT.x64.Debug to myapp\bin\Debug\netcoreapp2.0\win7-x64\publish folder. I also couldn't find out how to generate System.Memory package, so I'm manually replacing the dll in Nuget cache folder and publish folder. |
From @KrzysztofCwalina
From @ahsonkhan
Span.CopyTo<T>(ref Unsafe.As<byte, T>(ref destination.GetRawSzArrayData()), ref _pointer.Value, _length); cc @caslan |
There appear to be two distinct work items in this issue:
@ahsonkhan @jkotas @fujiy does that sound like an accurate representation of the current state of this issue? |
The workaround works without any update to the VS debugger for "portable" span. The internal bug in the VS debugger is blocking "fast span" debugging only which currently uses the naive solution:
I am not sure if we can implement ToString on Span. See related issue: https://github.com/dotnet/corefx/issues/21629#issuecomment-311789157 |
I do not think framework collections override ToString. E.g. |
Looks like dotnet/coreclr#15745 made the error here more helpful at least, so we can leave that as-is.
In that case, what else is there that needs to be done in CoreFX? |
and
I don't understand why we would not override ToString. For the sake of consistency with arrays and List? Is this consistency useful? Does it add value? On the other hand, it's close to impossible to debug code using spans. ToString override would not fix the overall issue (we still need to fix the debugger), but it would improve the situation a lot. I really worry that the current situation will seriously hamper the adoption of Span. cc: @terrajobst, @joshfree |
I think that the main problem is that there is no decent way to implement universal formatter for lists if you do not know what the items are. E.g. what would you use for seperators? Spaces, commas, new-lines, ...?
How would it improve the situation? To make |
I'm splitting this issue so the DebuggerTypeProxy discussion doesn't get lost in the ToString discussion. Please continue discussion on ToString over in https://github.com/dotnet/corefx/issues/26295 |
After the fix been released, should we "simplify" the slow span debugger proxy version? https://github.com/dotnet/corefx/blob/master/src/System.Memory/src/System/SpanDebugView.cs |
Yes! Ian and I discussed this already and he plans to simplify it to just a ToArray call, similar to what Fast Span does atm. |
It's difficult to debug programs that use spans because the span items cannot be easily inspected in the debugger.
The text was updated successfully, but these errors were encountered: