================
@@ -0,0 +1,57 @@
+// REQUIRES: target-windows
+// RUN: %build --compiler=clang-cl -o %t.exe -- %s
+// RUN: %lldb -f %t.exe -o "log enable windows process" -o r -o q | FileCheck 
%s
+
+#include <Windows.h>
+#include <string>
+
+int main() {
+  OutputDebugStringA("My string\nnext line\nBut this doesn't have trailing 
newline|");
+  OutputDebugStringW(L"OutputDebugStringW with some emojis 🦎🐊🐢🐍\n");
+  OutputDebugStringW(L"Another W1\n");
+  OutputDebugStringW(L"Another W2\n");
+  OutputDebugStringA("Some A1\n");
+  OutputDebugStringA("Some A2\n");
+  OutputDebugStringA("Some A3\n");
+
+  std::wstring maxW((1 << 19) - 4, L'A');
+  maxW.push_back(L'B');
+  maxW.push_back(L'\n');
+  OutputDebugStringW(maxW.c_str());
+
+  Sleep(100);
----------------
Nerixyz wrote:

I think the timing difference comes from logs directly writing to the output 
and `AppendSTDOUT` only sending an event to the `Debugger` (which eventually 
consumes it and prints). We log in the event thread (where we call 
`WaitForDebugEventEx`) and the `Debugger` listens in a different thread.

So if we do
```
OutputDebugString(messageA);
OutputDebugString(messageTooLong);
```
We either end up with
```
A
error: ...
OR
error: ...
A
```
because if the calls are immediately after each other, we might report the 
error before the `Debugger` wakes up.

> If LLDB decides to read messages at A, it will only see message A, but if the 
> event comes in later it will see message A and message B. The timing of the 
> event is up to Windows so by waiting we expect that it will generate the 
> event in that time.

We still get two separate events for these calls and, in the event thread, 
these are handled in order.

> Would it be possible to do this without the sleeps? If you were to `CHECK` 
> instead of `CHECK-NEXT`. What do you lose if you are not so strict?

I don't think that will work, as I need to check for both orders above. Could 
use `CHECK-DAG`, but that wouldn't ensure the relative order of debug message. 
What would work is using two `FileCheck` invocations. One to check for the 
output itself and one to check for errors.

https://github.com/llvm/llvm-project/pull/196395
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to