Closed Symbai closed 4 years ago
Are you talking about the Output window in Visual Studio? I can reproduce this issue there, but not when using a ConsoleTraceListener
.
Based on that and the fact that Debugger.Log(0, null, "abc bla\0, rest of text");
(which is used by DefaultTraceListener
) also exhibits this behavior, I think the issue is either in Debugger.Log
or in Visual Studio.
Win32's OutputDebugString just takes a string pointer, no length, so it will only consume up to a null terminator.
@stephentoub It seems CoreCLR also intentionally truncates strings with embedded NULs when they're logged using DebugInterface::SendLogMessage
. I don't know if VS uses that or OutputDebugString
, but I do wonder what is the reason behind truncating the strings there.
@svick Yes I'm talking about the output window in VS. It has cost me a bit of time figuring out why a line didn't contained the information it should have until I noticed a char array had a '\0' char in it. Personally I feel like it shouldn't be the case that it cuts off the text at this point there.
I think whatever way used for debugger logging, either will be ended calling OutDebugString as @stephentoub pointed out or it will truncate the message at the null terminator before sending it to the debugger interface.
https://source.dot.net/#System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Windows.cs,65 https://github.com/dotnet/coreclr/blob/46d98155f74fe3ff5ce82da033ead9fe108dda8f/src/vm/debugdebugger.cpp#L301
So this is by design I guess.
In this case I'm closing the issue then.
I'm not sure if this is intended or not but it Trace.Write and WriteLine cuts off text as soon as char '\0' appears. No error or exception, its just missing the rest of the text.
Repro:
results in output window text:
abc bla