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
Add .NET debugging attributes #14097
Conversation
1788bc1
to
f0dea34
Compare
Will look at this tomorrow - I've got Covid so I'm working more slowly in general. Will get to it eventually... |
@@ -23,6 +24,8 @@ namespace Google.Protobuf | |||
/// Immutable array of bytes. | |||
/// </summary> | |||
[SecuritySafeCritical] | |||
[DebuggerDisplay("Length = {Length}")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: ByteString
initially displays length rather than count to act more like array/span/memory. Also, ByteString
has a Length property rather than a Count property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! I particularly like the fact that there's no need to change the generated code at all :)
I've been working with a large Protobuf model and noticed debugging issues that can easily be improved. Add debugging attributes to collections, `ByteString`, and descriptors. No impact on runtime behavior. Debugger type proxies are what the debugger displays by default, but full data is available by selecting "Raw View". `RepeatedField` and `MapField` now display their item count. This is standard across .NET collections. For example, .NET's list and dictionary both display `Count = {Count}`. Note that previously, Protobuf collections displayed the result of `ToString`, which returned JSON. The JSON debug view isn't useful when there is too much content to display at once because it's truncated. That experience will be fairly common. Count benefits: * Always useful * Makes debugging Protobuf collections feel more like regular .NET collections * Collection contents is now easier to access with debugger type proxies No dependency between this PR and #13838. Each can be merged independently. **MapField before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/9dd3baa9-4432-446e-9049-1f7268d5be4c) **MapField after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/ac4aea33-e339-49e0-9a67-c174d2608393) **RepeatedField before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/16353785-bef4-4489-a3ab-de2437d51d4e) **RepeatedField after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/f3de7680-ded9-41d8-aac0-84a9e7b65c98) **ByteString before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/4febc400-1eb7-46ee-911e-a7698783a358) **ByteString after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/7635080e-9bb0-4f61-9a39-afbb9e575051) **Descriptor before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/5b89792b-a16a-4641-a50c-5355b5230b5d) **Descriptor after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/5047dc1e-c93b-43d5-bb8c-a6976a9ae6da) **TypeRegistry before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/d4aedf19-22cc-49b5-8717-9299e00abc85) **TypeRegistry after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/4a473595-74b9-40e2-96b8-2b103d5f44b0) Closes #14097 COPYBARA_INTEGRATE_REVIEW=#14097 from JamesNK:jamesnk/debugging f0dea34 FUTURE_COPYBARA_INTEGRATE_REVIEW=#14097 from JamesNK:jamesnk/debugging f0dea34 PiperOrigin-RevId: 567636087
I've been working with a large Protobuf model and noticed debugging issues that can easily be improved. Add debugging attributes to collections, `ByteString`, and descriptors. No impact on runtime behavior. Debugger type proxies are what the debugger displays by default, but full data is available by selecting "Raw View". `RepeatedField` and `MapField` now display their item count. This is standard across .NET collections. For example, .NET's list and dictionary both display `Count = {Count}`. Note that previously, Protobuf collections displayed the result of `ToString`, which returned JSON. The JSON debug view isn't useful when there is too much content to display at once because it's truncated. That experience will be fairly common. Count benefits: * Always useful * Makes debugging Protobuf collections feel more like regular .NET collections * Collection contents is now easier to access with debugger type proxies No dependency between this PR and #13838. Each can be merged independently. **MapField before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/9dd3baa9-4432-446e-9049-1f7268d5be4c) **MapField after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/ac4aea33-e339-49e0-9a67-c174d2608393) **RepeatedField before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/16353785-bef4-4489-a3ab-de2437d51d4e) **RepeatedField after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/f3de7680-ded9-41d8-aac0-84a9e7b65c98) **ByteString before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/4febc400-1eb7-46ee-911e-a7698783a358) **ByteString after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/7635080e-9bb0-4f61-9a39-afbb9e575051) **Descriptor before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/5b89792b-a16a-4641-a50c-5355b5230b5d) **Descriptor after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/5047dc1e-c93b-43d5-bb8c-a6976a9ae6da) **TypeRegistry before:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/d4aedf19-22cc-49b5-8717-9299e00abc85) **TypeRegistry after:** ![image](https://github.com/protocolbuffers/protobuf/assets/303201/4a473595-74b9-40e2-96b8-2b103d5f44b0) Closes #14097 COPYBARA_INTEGRATE_REVIEW=#14097 from JamesNK:jamesnk/debugging f0dea34 FUTURE_COPYBARA_INTEGRATE_REVIEW=#14097 from JamesNK:jamesnk/debugging f0dea34 PiperOrigin-RevId: 567636087
I've been working with a large Protobuf model and noticed debugging issues that can easily be improved.
Add debugging attributes to collections,
ByteString
, and descriptors. No impact on runtime behavior. Debugger type proxies are what the debugger displays by default, but full data is available by selecting "Raw View".RepeatedField
andMapField
now display their item count. This is standard across .NET collections. For example, .NET's list and dictionary both displayCount = {Count}
.Note that previously, Protobuf collections displayed the result of
ToString
, which returned JSON. The JSON debug view isn't useful when there is too much content to display at once because it's truncated. That experience will be fairly common.Count benefits:
No dependency between this PR and #13838. Each can be merged independently.
MapField before:
MapField after:
RepeatedField before:
RepeatedField after:
ByteString before:
ByteString after:
Descriptor before:
Descriptor after:
TypeRegistry before:
TypeRegistry after: