dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.24k stars 4.73k forks source link

Unable to get JITDisasm with dotnet-run #2842

Closed livarcocc closed 4 years ago

livarcocc commented 7 years ago

From @am11 on July 4, 2017 17:34

Description

The CLR configuration knobs documentation suggests that if we set the environment variables, the knobs variables set by the environment shall be abided.

https://github.com/dotnet/coreclr/blob/38a2a69/Documentation/project-docs/clr-configuration-knobs.md

This holds if we build CoreCLR and run the app via corerun, but not when running with dotnet.exe/corehost.exe.

Steps to reproduce

# powershell
mkdir inspectjit
cd inspectjit
dotnet new console

# set env var as per the documentation
$env:COMPLUS_JitDisasm="Main"

dotnet restore
dotnet run

Expected behavior

Dumps the disassembly for method Main on stdout as per the documentation.

Seems like corehost or CLI are clearing output emitted by CoreCLR.

Actual behavior

Only Hello World! is emitted on stdout.

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.4)

Product Information:
 Version:            1.0.4
 Commit SHA-1 hash:  af1e6684fd

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.4

Copied from original issue: dotnet/cli#7072

livarcocc commented 7 years ago

Moved it here because this is something that the host should honor. I published the app and ran it using dotnet and still did not get the disassembly printout, and in this case, there is no CLI involved.

Petermarcu commented 7 years ago

@gkhanna79 any insight here? @steveharter to take a look. Corehost is used for development of the runtime itself, my assumption is we didn't necessarily plumb all the same options through to the .NET Core App model.

gkhanna79 commented 7 years ago

Do you see the output when corehost_trace=1 is enabled @livarcocc ?

am11 commented 7 years ago

Thanks @livarcocc!

@gkhanna79, yes I can see the output dump when setting corehost_trace: $env:COREHOST_TRACE=1;dotnet run. Can the other CoreCLR knobs be honored by setting the documented COMPLUS_* variables in a similar fashion?

am11 commented 7 years ago

my assumption is we didn't necessarily plumb all the same options through to the .NET Core App model

@Petermarcu, if the environment values are transparently propagated by host to the runtime, would it still involve lots of plumbing? Alternatively, would it make sense to introduce a switch in CLI, say --jit-debug <comma separated list of knob IDs without COMPLUS_ prefix>, without requiring environment variables propagation from host to runtime?

steveharter commented 7 years ago

So if output works with corehost_trace=1 + dotnet run then it appears stdout is being redirected to stderr?

Also here's some additional doc with information including that a debug version of CoreClr is required: https://github.com/dotnet/coreclr/blob/38a2a69c786e4273eb1339d7a75f939c410afd69/Documentation/building/viewing-jit-dumps.md#setting-configuration-variables

gkhanna79 commented 7 years ago

Correct.

steveharter commented 7 years ago

@gkhanna79 correct on which comment? :)

I'll debug this soon to see what exactly is going on.

steveharter commented 7 years ago

At least for 2.0, I think the biggest factor here is that in order to get the Jit output, CoreClr needs to be compiled in Debug mode. Provided a Debug version is used, and the appropriate COMPlus_JitDump is set, the Jit output should appear in stdout. You can use corehost_trace=1 to see where the CLR is being loaded from.

On 2.0, I verified success under various configurations: 1) With and without a RID 2) Running via dotnet exec, dotnet run and [myapp].exe directly (with a RID)

With a RID, you can use robocopy as mentioned in https://github.com/dotnet/coreclr/blob/38a2a69c786e4273eb1339d7a75f939c410afd69/Documentation/building/viewing-jit-dumps.md#setting-configuration-variables to copy the locally build Debug CoreClr to the appropriate bin folder so it is picked up and used. I don't think we have an official\public Debug version available, so you must build it yourself.

Without a RID, there is more\different work to do to ensure the Debug build is found, as the bin folder is not considered as a CoreClr location for portable apps.

steveharter commented 6 years ago

Closing; Debug mode is currently required