[PATCH] ntdll: Truncate and ellipsize debug output if it's too long.

Esme Povirk (she/they) esme at codeweavers.com
Tue Aug 31 12:49:28 CDT 2021


On Tue, Aug 31, 2021 at 5:03 AM Alexandre Julliard <julliard at winehq.org> wrote:
> > I would still like to figure this out for the occasions when Mono
> > produces really long trace outputs.
>
> The best is to send them through debugstr_a/w, but you can also truncate
> or wrap them manually as seems appropriate. You don't need to know the
> exact buffer length, you can use say 600 chars (two debugstr's worth).

The trouble is that Mono likes to send debug output in pieces,
especially the trace functionality where each argument is a single
call to mono_print_handler_fn. To illustrate, I tried modifying it to
print just one line with debugstr_a and got call traces like this:

00fc:fixme:mscoree:mono_print_handler_fn "ENTER:c (wrapper
managed-to-native) System.IO.MonoIO:Write
(intptr,byte[],int,int,System.IO.MonoIOError&)("
00fc:fixme:mscoree:mono_print_handler_fn "0000000000000014"
00fc:fixme:mscoree:mono_print_handler_fn ", "
00fc:fixme:mscoree:mono_print_handler_fn
"[System.Byte[]:[1024]0000000001457a40]"
00fc:fixme:mscoree:mono_print_handler_fn ", "
00fc:fixme:mscoree:mono_print_handler_fn "0"
00fc:fixme:mscoree:mono_print_handler_fn ", "
00fc:fixme:mscoree:mono_print_handler_fn "15"
00fc:fixme:mscoree:mono_print_handler_fn ", "
00fc:fixme:mscoree:mono_print_handler_fn "[BYREF:000000000011f140]"
00fc:fixme:mscoree:mono_print_handler_fn ")\n"

We could keep track of the total line length in some sort of TLS, but
it feels like it'd be better to do that in the common debug code where
we already have a TLS structure than in mscoree. There's also a
possibility that the length stored by mscoree will be off if other
Wine traces occur in the same thread between these calls (which would,
of course, garble the output, so maybe that's an argument for having a
string buffer in mscoree, but it doesn't feel very clean to me as we'd
have to hard-code the maximum length).

On the Mono side, that line is printed by a single method,
mono_trace_enter_method
(https://github.com/madewokherd/mono/blob/develop/mono/mini/trace.c#L147),
but I'd rather not modify Mono code any more than I have to because it
makes merges more difficult, and it's not obvious to me how to improve
it anyway. At the moment, Mono doesn't have access to debugstr_a, but
I guess I could throw in another copy of debug.c.

I've had one case where a single method name and its argument types
was enough to overflow the buffer on its own.



More information about the wine-devel mailing list