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

Add GetProcessEnvironment command to diagnostics server #40556

Merged
merged 12 commits into from
Aug 14, 2020

Conversation

josalem
Copy link
Contributor

@josalem josalem commented Aug 7, 2020

These changes send the Environment block via the GetProcessEnvironment command in the Diagnostics IPC Protocol.

The environment block is retrieved in the standard null delimited list of strings form, and is sent as an Array<Array<WCHAR>> in the IPC protocol. In other words, it is retrieved as

key=val\0key=val\0\0

and sent as (the | are logical separators and not part of the data)

2|8|key=val\0|8|key=val\0

Note that the tests do not print the bytes of the payload since they include the environment where the tests are run.

closes #40572

CC @dotnet/dotnet-diag @jander-msft

@josalem josalem added this to the 5.0.0 milestone Aug 7, 2020
@josalem josalem requested review from noahfalk, jander-msft, sywhang and a team August 7, 2020 23:51
@josalem josalem self-assigned this Aug 7, 2020
@ghost
Copy link

ghost commented Aug 7, 2020

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

@tommcdon
Copy link
Member

tommcdon commented Aug 8, 2020

GH issue tracking this PR: #40572

@josalem
Copy link
Contributor Author

josalem commented Aug 10, 2020

Win64 libraries test failure is #40625

@davmason
Copy link
Member

Two comments:

  1. What happens if an environment variable has a pipe character in it? As far as I know it's perfectly legal to have an environment variable like "Foo=Bar|" and that seems like it would break your scenario since you use | as a separator

  2. We already have a key/value pair format we use in EventPipe for filter arguments that uses semi-colons as delimiters key1=value1;key2=value2 and can escape using quotes. We should be intentional about whether or not we use the same format here, since it's solving the same issue

@josalem
Copy link
Contributor Author

josalem commented Aug 10, 2020

  • What happens if an environment variable has a pipe character in it? As far as I know it's perfectly legal to have an environment variable like "Foo=Bar|" and that seems like it would break your scenario since you use | as a separator
  • We already have a key/value pair format we use in EventPipe for filter arguments that uses semi-colons as delimiters key1=value1;key2=value2 and can escape using quotes. We should be intentional about whether or not we use the same format here, since it's solving the same issue

Ah, @davmason, the | in that block was meant to just separate the bytes that would be written. It's not actually a string with that character in it. A more literal representation would be this:

[ nElems  ] [ n chars ] [chars                         ] [n chars  ] [ chars                        ]
00 00 00 10 00 00 10 00 'k' 'e' 'y' '=' 'v' 'a' 'l' '\0' 00 00 10 00 'k' 'e' 'y' '=' 'v' 'a' 'l' '\0'

The event block is being sent as a length-prefixed array of strings which themselves are sent as length-prefixed arrays of wchars. It's not using characters as delimiters.

Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

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

LGTM mostly.

src/coreclr/src/vm/processdiagnosticsprotocolhelper.cpp Outdated Show resolved Hide resolved
src/tests/tracing/eventpipe/processinfo/processinfo.cs Outdated Show resolved Hide resolved
src/coreclr/src/vm/processdiagnosticsprotocolhelper.cpp Outdated Show resolved Hide resolved
John Salem added 2 commits August 12, 2020 15:39
* allow for additions to this command without having to version it later
Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM : )

}
CONTRACTL_END;

// Array<Array<WCHAR>>
Copy link
Member

Choose a reason for hiding this comment

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

In the overflow case this still writes lots of data even though GetEnvironmentBlockSize() specified only 4 bytes would be written. Separately I would assume in the overflow case we'd want to return an error in the header and write 0 bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic should leave _nEnvEntries set to 0, so the payload would end up saying the continuation has 4 bytes and those 4 bytes should be the number 0 since there won't be any entries in the array. I could modify it so that the continuation length in the message payload is 0 instead and let the user treat that as an error. Would that be preferable?

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLRTestPriority>0</CLRTestPriority>
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
<JitOptimizationSensitive>true</JitOptimizationSensitive>
Copy link
Member

Choose a reason for hiding this comment

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

We don't really care how the JIT optimizes this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. This was held over from doing a copy/paste of the proj file for another event pipe test. I'll remove.

ResumeRuntime = 0x01,
GetProcessInfo = 0x00,
ResumeRuntime = 0x01,
GetProcessEnvironment = 0x02
Copy link
Member

Choose a reason for hiding this comment

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

Is there a companion PR to the diagnostics repo with the spec update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There will be. It hasn't been created yet.

@josalem
Copy link
Contributor Author

josalem commented Aug 13, 2020

Remaining failure is #34472. If there isn't any opposition, I'll merge this this afternoon.

@josalem josalem changed the title Include Environment Block in Process Info command Add GetProcessEnvironment command to diagnostics server Aug 14, 2020
@josalem josalem merged commit 28e2d54 into dotnet:master Aug 14, 2020
@josalem josalem deleted the dev/josalem/envblock-process-info branch August 14, 2020 00:52
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
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.

Add Environment block via the ProcessInfo command in the Diagnostics IPC Protocol
7 participants